我正在尝试在控制器上请求操作的应用程序,并接收带有更新信息的模型。步骤很简单,
但是,模型不会更新!
代码:
<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 Page代码:
<!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)
答案 0 :(得分:1)
暂停您的javascript代码(例如使用firebug)并确认您的formdata确实按预期发送。
如果formData看起来是正确的,请在您的Controller Action中放置一个中断并验证模型构建器是否已正确将formdata转换为模型。
奖金琐事:默认的模型制作者不会将“1”翻译为“真”,这可能是你的问题吗?