【发布时间】:2013-07-19 14:25:23
【问题描述】:
我有一个编辑表单,它在文本框中有一个标签和当前值,我想检查表单中的值在提交表单时是否已更改。 这是表格
<fieldset>
<legend>Module <small>Edit</small></legend>
@using (Html.BeginForm("Edit", "Module"))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(m=>m.Id)
for(var i = 0; i < Model.Properties.Count(); i++)
{
<label class="label">@Model.Properties[i].Name</label>
<div class="input-block-level">@Html.TextBoxFor(model => Model.Properties[i].Value, new { @value = Model.Properties[i].Value })</div>
}
<div class="form-actions" id="buttons">
<button type="submit" class="btn btn-primary" id="Submit">Save changes</button>
@Html.ActionLink("Cancel", "ModuleList", null, new { @class = "btn " })
</div>
}
</fieldset>
这个结果
如何检查表格是否已更改?我的控制器的httppost方法目前看起来像这样
[HttpPost]
public ActionResult Edit(EditModule module)
{
if (ModelState.IsValid)
{
_repository.SaveModuleEdits(module);
Information("Module was successfully edited!");
return RedirectToAction("ModuleList", "Module", new {area = "Hardware"});
}
Error("Edit was unsuccessful, if the problem persists please contact admin!");
return RedirectToAction("ModuleList", "Module", new { area = "Hardware" });
}
}
【问题讨论】:
-
是的,但它是否必须检查正在编辑的表单中的值?
-
您在寻找 javascript 解决方案还是服务器端解决方案?
-
我还应该要求检查它是否被编辑过。只是想了解一下,以便我可以提供适当的建议。
-
任何都可以,我只需要能够将我的表单转发到控制器的 httppost 操作,并且该操作应该能够知道是否有编辑。
-
如果我猜测需要知道是否有编辑,我会说您想更新已更改的记录。假设就是这样。 EF 有 changetracker 来跟踪更改的内容。我用它来实施审计。类似jmdority.wordpress.com/2011/07/20/…
标签: asp.net-mvc asp.net-mvc-4 http-post