【发布时间】:2016-05-11 06:36:01
【问题描述】:
这是根据我的问题:
How to pass array created from jQuery to controller method?
这是我的控制器返回部分视图:
public ActionResult PartialViewChild(int id)
{
//stmts /*model is assigned here */
return PartialView("ChildPartialView", model);
}
我现在的问题是,从我的控制器操作返回的视图不是由$.ajax() 调用呈现的。我在成功函数中放了一个调试器,它从来没有打到那里。所以,偶然的机会,我也在 ajax 调用中添加了一个错误函数,例如,
var id=currentSelected.Id;
$.ajax({
url: "@(Url.Action("PartialViewChild", "ControllerChild")",
type: "POST",
data: JSON.stringify({id : id}),
cache: false,
success: function (result) {
$("#id1").html(result);
},
error: function (data, errorThrown) {
alert('request failed :' + errorThrown);
}});
我还发现,id 为“id1”的 div 必须为空才能正确呈现局部视图。但是,一开始的那个 div 会呈现一个 EmptyView,比如,
<div id="id1">
@{Html.RenderPartial("ChildPartialView", new ChildPartialModel());}
</div>
并基于 ajax 调用,我想用返回的结果填充该 div(现在所有属性都将具有值).. 但是,不幸的是,在这里我只有来自 ajax 调用的错误警报:() 告诉我有一个“解析错误”。
谁能告诉我如何改正它?
编辑:
这是我的局部视图:
@model Models.ChildColumnsModel
<div>
<span>@Html.LabelFor(c => c.Phone_Number):</span>
<span>@Html.TextBoxFor(c=> c.Phone_Number)</span>
</div>
// like this it has all its attributes...
在我的控制器中:
public PartialViewResult PartialViewChild(int id)
{
var model=child.GetReletedInfo(id); /*proper results are returned here which is of ChildColumnsModel type */
return PartialView("ChildPartialView", model);
}
【问题讨论】:
-
显示完整的部分视图代码。
-
和更多关于 ("ChildPartialView", model);
-
试试 eidt var model=child.GetReletedInfo(id)??新的 ChildColumnsModel();
-
这个stmt的实际用途是什么?
-
这句话的意思是:如果 child.GetReletedInfo(id) 为 null 则创建一个新的 ChildColumnsModel
标签: jquery ajax asp.net-mvc partial-views renderpartial