C#MVC视图之间没有提交传递对象

我很抱歉我的错别字。我正在研究概念certificateC#ASP.NET MVC应用程序,我需要在没有post和get时在两个视图之间传递数据。 一个视图启动modal dialog,我需要它们之间的通信。 我们正在使用JQuery。

我有一个名为Charges.cshtml的视图,带有数据网格。 数据网格的第一列可以具有span元素或链接元素,这取决于将告知电荷是具有单个还是多个描述的属性。 视图如下所示。

收费

如果费用有多个描述,用户将点击相应的描述链接(在这种情况下为Description2),将打开一个modal dialog,显示如下所示的各种描述

多个描述

现在,在此modal dialog中,用户将确认/选择一个描述。 现在我需要关闭modal dialog并更新所选电荷的描述,如下所示

更新说明

这里的难点是如何在两个视图之间传递数据。 我可以通过控制器或通过JavaScript传递数据。

我尝试了各种方法将所选费用从Charges.cshtml传递到LoanCharge控制器中的LoadLoanChargeDescriptions方法,如json serialize,ViewData,ViewBag,TempData等,但没有用。 我可以传递简单的数据类型,如int,string,float但不是整个对象。 我觉得我需要将CurrentDescription和Descriptions传递给我的控制器,并且我需要将其移动到其他部分。 我试图传递字符串列表,但无法看到如何在控制器中访问它们,因为我在控制器中计数为0。 我能够打开多个描述UI的弹出窗口(现在只是添加了Hello文本)

请参阅下面的我的代码片段

Charges.cshtml

@model ChargeViewModel @using (Html.FAFBeginForm()) { 
//.....
@if(Model.IsMultipleMatch) { var loanCharge = Model as ChargeViewModel; if (loanCharge.IsMultipleMatch == true) { //string vm = @Newtonsoft.Json.JsonConvert.SerializeObject(loanCharge); @loanCharge.Description } } else { Model.Description }
} public class ChargeViewModel { public string Description {get;set;} public bool IsMultipleMatch {get;set;} public List Descriptions {get;set;} } public class LoanChargeController { public ActionResult LoadLoanChargeDescriptions() { // get data here and pass/work on return View("_PartialMultipleMatchPopup", null); } }

在Review.js

 function ShowMatchingDescriptions(popUpURL, windowProperties, w, h) { try { var left = (screen.width / 2) - (w / 2); var top = (screen.height / 2) - (h / 2); var properties = windowProperties + "dialogwidth:" + w + "px;dialogheight:" + h + "px;dialogtop:" + top + "px;dialogleft:" + left + "px;scroll:yes;resizable:no;center:yes;title:Matching Lender's Fee;"; $.when( window.showModalDialog(popUpURL, window, properties) ) .then(function (result) { var childWindow = result; }); } catch (err) { alert("Error : " + err) } } 

更新1

我更新了我的问题并发布了更多细节。

提前致谢。

更新2

请在下面链接查看我的解决方案。

父窗口和子窗口之间的MVC传递模型

你为什么不使用AJAX传递数据?

  function ChargeViewModel() { this.Description =''; this.IsMultipleMatch =false; } var chargeViewModel= new ChargeViewModel(); var data = JSON.stringify({ 'chargeViewModel': chargeViewModel }); $.ajax({ contentType: 'application/json; charset=utf-8', dataType: 'html', type: 'POST', url: '@Url.Action("LoadLoanChargeDescriptions", "LoanChargeController")', data: data, success: function (result) { //result will be your partial page html output }, failure: function (response) { } }); 

然后你必须像这样更改控制器:

 public ActionResult LoadLoanChargeDescriptions(ChargeViewModel chargeViewModel) { // get data here and pass/work on return View("_PartialMultipleMatchPopup", null); } 

让我知道你有疑问..