【发布时间】:2013-11-29 09:56:59
【问题描述】:
我有一个 cshml 视图,我在 div 中调用另一个视图,如下所示
<div class="family_name" id="DisplayPartilView">
<div class="content_part content_part2">
<h1 class="family_nameStyle">Additional Contacts <button id="AddEmergencyContact" jid="@ViewData["offerId"].ToString()" class="btn highlight" data-dismiss="modal" >
+</button></h1>
<h6> </h6>
<div id="listChildContactAuthorisationsCI" class="table_form">
<table style="width: 640px;" id="CIAuthtable">
<tr>
<td>Contact Name</td>
<td title="This contact is authorised to drop off and collect this child.">Collection</td>
<td title="This contact is an emergency contact for the child.">Emergency</td>
<td title="This contact can authorise the child to participate in centre excursions.">Excursion</td>
<td title="This contact can authorised the administering of medication to the child.">Medical</td>
</tr>
@if (Model.ChildContactAuthorisations != null)
{
@Html.EditorFor(x => x.ChildContactAuthorisations)
}
</table>
</div>
</div>
</div>
此视图与其他视图共享,因此它位于 Shared/Editor Template 文件夹中。 我正在使用来自另一个页面(addcontact)的ajax,如下所示
$.ajax({
data: $.parseJSON('{"Id" : "' + EntityId + '"}'),
type: 'POST',
url: '@(Url.Action("GetAdditionalContacts", "QkEnrolment"))',
success: function (result) {
alert(result.outerHTML);
$('div#listChildContactAuthorisationsCI').html(result);
},
error: function () {
alert('Error');
}
});
添加联系人后,控件将跟随控制器功能进入控制器
public ActionResult GetAdditionalContacts(int Id)
{
Id = Convert.ToInt32(TempData["offerId"]);
User user = DependencyResolver.Current.GetService<ICrud<User>>().Where(x => x.Username == WebSiteContext.Current.UserId).FirstOrDefault();
var offer = _offerRepo.Get(Id);
var child = _childRepo.Get(offer.Child.Id);
var childStubContactAuthorisations = child.GetContactAuthorisations().ToList();
List<Section_ChildContactAuthorisation> ChildContactAuthorisations1 = GetAggregateChildContactAuthorisations(user, childStubContactAuthorisations);
TempData["offerId"] = Id;
return Json(ChildContactAuthorisations1, JsonRequestBehavior.AllowGet);
}
但我想用从上述控制器函数返回的模型(包含新添加的联系人)更新视图。但是视图没有更新。
任何人都可以帮助我吗 谢谢, 维迪亚
【问题讨论】:
-
您正在返回
json并期待 ajax 成功中的html。我可以知道为什么吗? -
我是第一次这样做...错误地发生了这种情况...您能告诉我正确的方法吗?
标签: c# ajax asp.net-mvc