我正在尝试执行请求控制器上的操作并接收带有更新信息的模型的应用程序。步骤很简单,
- 在表格上填写一些信息。
- 单击某个按钮以调用控制器上的操作。
- 该操作更新接收到的模型并使用 PartialView 方法将其发回。
但是,模型不回更新!
代码:
<div id="div-dialog"> // THIS IS A DIALOG JQUERYUI
<div id="div_toolbar" class="ui-widget-header ui-corner-all"> //THIS IS A TOOLBAR JQUERYUI
<div style="margin-right: auto; margin-left: auto; width: 420px">
<button id="btn_novo">Novo</button>
<button id="btn_gravar">Gravar</button>
<button id="btn_limpar">Limpar</button>
<button id="btn_excluir">Excluir</button>
</div>
</div>
</div>
<div id="partial-render"> //HERE GOES THE PARTIAL VIEW
@Html.Partial("AvaliationPeriodPartial")
</div>
<script type="text/javascript">
$(function () {
$('#div-dialog').dialog({
height: 'auto',
width: 600
});
$('#btn_novo').button({ icons: { primary: "ui-icon-document"} }).button('enable').click(function () {
/* ON THIS FUNCTION I SERIALIZE THE INPUTS TO SEND IT TO THE ACTION ON CONTROLLER
TO UPDATE THE INFORMATION */
var formData = $('input').serialize();
$('input[disabled]').each(function () {
formData = formData + '&' + $(this).attr('name') + '=' + $(this).val();
});
//HERE THE AJAX CALL
$.post('@Url.Action("teste", "Import")', formData, function (html) {
$('#partial-render').html(html);
}, 'html');
});
</script>
这是_Layout页面代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bem-vindo | @ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/redmond/jquery-ui-1.9.1.custom.min.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.8.3.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.9.2.custom.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/MicrosoftAjax.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"></script>
</head>
<body>
@RenderBody()
</body>
</html>
这是 PartialView 的代码:
@model GdaeMVC4.Models.ScreenModels.AvaliationPeriod
@Html.LabelFor(m => m.IdAvaliation)
@Html.TextBoxFor(m => m.IdAvaliation)
@Html.TextBoxFor(m => m.Description)