嗨,我有以下 ViewUserControl:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<table>
<tr>
<td><%= Html.TextBox("") %></td>
<td><button type="button" id="workType-open-button" class="t-button" onclick="modalWin('http://localhost:29357/WorkType/SelectForTR')">Select</button></td>
</tr>
</table>
<script type="text/javascript">
function modalWin(url) {
if (window.showModalDialog) {
window.showModalDialog(url, "Select work type", "dialogWidth:700px;dialogHeight:450px");
}
else {
window.open(url, 'Select work type', 'height=700,width=450,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no ,modal=yes');
}
}
</script>
我用它来编辑一个类的下一个属性:
[UIHint("WorkTypes"), Required]
public int WorkType { get; set; }
在 UserControl 我有以下代码:
[HttpPost]
[GridAction]
public ActionResult InsertTimeRegistration()
{
TimeRegistrationViewModel newT = new TimeRegistrationViewModel();
if (TryUpdateModel(newT))
{
//The model is valid - insert the time registration.
newT.Employee = 6;
repo.AddTimeRegistration(newT);
}
return View(new GridModel(repo.GetAllTimeRegistrationOfAnEmployee(6)));
}
问题是,如果我从控件中删除按钮,它可以正常工作,但是使用按钮它不会更新模型。POST 的参数在编辑表单中插入了值,但记录没有保存到数据库。
如果可以的话,请给我一个建议。
谢谢