I have cratet simple Model
public class ModelTest
{
public string MyValue { get; set; }
}
With simple controller
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" });
}
}
With view for Start
<body>
<h1>testing</h1>
<div id="editorDiv">
<% Html.RenderPartial("Editor", Model); %>
</div>
</body>
And control Editor:
<%@ 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" />
<% } %>
EDIT: (I had little time and I wrote a little understandable)
I'm have initialValue in textbox from model:
Then I wrote text 'Test' into it and press 'Zapisz' button. In my controller post method 'Editor' value should be changed from 'Test' to 'Test Post!' and in view textbox (input) shold have value 'Test Post!'. Instead from Html.TextBoxFor(model => model.MyValue) I get old value 'Test' but from <%: Model.MyValue %> I get current value.
Why textBox loses value from model?