在mvc方法之间传递数据

时间:2016-05-12 19:42:04

标签: json asp.net-mvc methods

string jsonoutput = JsonConvert.SerializeObject(ReportDefenitionJson);

如何在将Json返回到视图的同时将数据从一个方法传递到另一个方法?这是我的意思和例子:

public JsonResult SubmitReport(string JsonStringSend, Guid ReportId)
{
    dynamic JSend = JObject.Parse(JsonStringSend);
    var schema = JsonSchema4.FromType<ReportItem>();
    var schemaData = schema.ToJson();
    var errors = schema.Validate(JSend.JsonString);
    schema = JsonSchema4.FromJson(schemaData);
    Guid ReportID = Guid.NewGuid();
    Guid GetUserID = Guid.NewGuid();
    DateTime CurrentDateTime = DateTime.Now;
    string ReportCreator = GetUserID.ToString() + " : " + CurrentDateTime.ToString();
    JObject Report = (JObject)JSend["JsonString"];
    Report["ReportID"] = ReportID.ToString();
    Report["CreatedBy"] = ReportCreator;
    string ReportDefenitionJson = Report.ToString();
    string ReportIdJsonFileName = ReportID.ToString() + ".json";
    this.StoreReportDefenition(ReportDefenitionJson, ReportIdJsonFileName);

    List<ReturnJsonErrors> ReturnJson = new List<ReturnJsonErrors>();
    ReturnJson.Add(new ReturnJsonErrors { Success = true, Errors = null });

    return Json(ReturnJson, JsonRequestBehavior.AllowGet);
}

public void StoreReportDefenition(string ReportDefenitionJson, string ReportIdJsonFileName)
{
     string jsonoutput = JsonConvert.SerializeObject(ReportDefenitionJson);
     byte[] byteArray = Encoding.UTF8.GetBytes(jsonoutput);
     MemoryStream fileContents = new MemoryStream(byteArray);
     var fullAddress = string.Format("11a5/Reporting/Reports/Report/{0}", ReportDefenitionJson);
     AmazonS3Repository repo = new AmazonS3Repository(InRollPlus.Shared.ConstantVals.ConstantItem.AWS_ACCESS_KEY, InRollPlus.Shared.ConstantVals.ConstantItem.AWS_SECRET_KEY);
     repo.PutFile(fileContents, fullAddress, null, "data.json", false);
}

如何在将Json返回到视图的同时将ReportDefenitionJsonReportIdJsonFileName传递给方法StoreReportDefenition

1 个答案:

答案 0 :(得分:0)

使用this.StoreReportDefenition(ReportDefenitionJson, ReportIdJsonFileName);将传递数据并完美执行该方法。