下面是我用来渲染局部视图的AJAX调用
$.ajax({
url: '/apps/Applications',
dataType: 'html',
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
type: 'post',
data: $('#TaskList').serialize()
//data: $('#form_' + id).serialize()
//data: { appID: ID }
}).success(function (result) {
$('#OpenApplications').show().append('<div class="tab-pane active" id="subnav_' + id + '" >' + result + '</div>');
}).error(function (xhr, status) {
alert(status);
});
我的部分视图控制为
@Html.TextBoxFor(model => model.Application.ID, new { id = "appid"})
我在后端获得Application.ID
的值,但在前端,该值不会绑定到application.ID
的控件。
以下是控制器代码
data.TaskChanges = new TaskHistory(data.Application.ID, data.Application.InternalStatus, data.Application.Processor, data.Application.AssessorComments, data.Application.InternalNotes);
// we create if empty
if (data.OpenTasks == null)
{
data.OpenTasks = new Dictionary<int, string>();
}
// now we add if not present
if (!data.OpenTasks.ContainsKey(data.Application.ID))
{
data.OpenTasks.Add(data.Application.ID, data.Application.PID);
}
return PartialView("OpenApplications", data);
任何帮助?
答案 0 :(得分:0)
尝试在控制器方法
中使用以下行ModelState.Clear();