【发布时间】:2011-07-15 15:38:19
【问题描述】:
我有一个简单的模型
public class ModelTest
{
public string MyValue { get; set; }
}
使用简单的控制器
public class ModelTestController : Controller
{
public ActionResult Editor()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Editor(ModelTest modelTest)
{
modelTest.MyValue += " Post!";
return View(modelTest);
}
public ActionResult Start()
{
return View(new ModelTest { MyValue = "initial value" });
}
}
开始视图
<body>
<h1>testing</h1>
<div id="editorDiv">
<% Html.RenderPartial("Editor", Model); %>
</div>
</body>
和控件编辑器:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcTest.Models.ModelTest>" %>
<% using (Ajax.BeginForm("Editor", new AjaxOptions { UpdateTargetId = "editorDiv", })) { %>
Current real Value: <%: Model.MyValue %> <br />
<%: Html.TextBoxFor(model => model.MyValue) %> <br />
<input type="submit" value="Zapisz" id="saveInput" />
<% } %>
编辑:(时间不多,写的有点明白)
我在模型的文本框中有初始值:
然后我在其中写入文本“测试”并按下“Zapisz”按钮。在我的控制器发布方法中,“编辑器”值应从“测试”更改为“测试发布!”并且在视图文本框(输入)中应该有值'Test Post!'。而不是从 Html.TextBoxFor(model => model.MyValue) 我得到旧值 'Test' 但从 我得到当前值。
为什么 textBox 会失去模型的价值?
【问题讨论】:
-
嗯,我不明白你的问题。
标签: c# asp.net ajax asp.net-mvc-3