我在ASP.NET MVC3中使用Ajax.BeginForm帮助程序提交一个表单,该表单用服务器上设置的表单中的新值替换自己.但是当我使用像Html.TextBoxFor这样的帮助器时,我得到了提交的值,而不是我在服务器上插入模型的值.
例如;我在动作中将SomeValue设置为4并将其显示在文本框中.我将值更改为8,点击提交,并期望在文本框中将值更改回4,但由于某种原因它保持为8.但如果我输出SomeValue而不使用Html助手,则表示4.任何人都有一些关于到底是怎么回事?
我的控制器:
public ActionResult Index(HomeModel model) { model.someValue = 4; if (Request.IsAjaxRequest()) return PartialView(model); return View(model); } public class HomeModel { public int? SomeValue { get; set; } }
我的观点(请注意,我的布局页面中没有所有必需的javascript):
<div id="ajaxtest"> @using(Ajax.BeginForm(new AjaxOptions{ InsertionMode = InsertionMode.Replace,UpdateTargetId = "ajaxtest",HttpMethod = "Post" })) { @Html.TextBoxFor(model => model.someValue) <input type="submit" value="Update" /> } </div>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。