I'm not sure what I'm doing wrong. I have never had this problem before, or maybe I have, but I never noticed. I have a partial view page. When the page is submitted, the model is checked for an identifier. If so, it updates the record. If not, he creates a new one. Pretty standard. Once this is done, the model will return to viewing. The problem that I seem to encounter is that it is not updated with any changes to the model. This is the same model that was published. So here is the code. I created a completely new project and it still does not work.
In addition, I used Firebug to look at the raw data coming back, and this is still the same model.
Here is the controller:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Test()
{
return this.View(new Test());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestDetailPost(Test testin)
{
Test test = new Test();
test.Id = "1";
test.Name = "Guy";
return this.PartialView("TestDetail", test);
}
Here is the "Test" view:
@model WebAppTest.Models.Test
@using (Ajax.BeginForm("TestDetailPost", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "TestDetail" }))
{
<p><input type="submit"/></p>
<div id="TestDetail">
@{ Html.RenderPartial("TestDetail", Model); }
</div>
}
Here is the "Test Detail" view:
@model WebAppTest.Models.Test
<p>@Html.TextBoxFor(a => a.Id)</p>
<p>@Html.TextBoxFor(a => a.Name)</p>
And the model:
public class Test
{
public string Id { get; set; }
public string Name { get; set; }
}
So, I found that if I remove the “Test testin” from the TestDetailPost action, it will return the model I created. If I do not, it will simply return the same model that was published. Of course, I am not making any changes to the DB or anything like that, the code above is just trying to understand why this is happening.
Here are the details of what I'm using:
MVC5 jQuery 1.11.1 jquery.unobtrusive-Ajax
I updated all the files to the latest version using NuGet.