I am doing something fundamentally wrong. I have created a simple example of my problem.
I have a simple class as follows:
public class Example
{
public string Text { get; set; }
}
I have created two methods on my controller
This is the view page you hit. It creates a new Example
object.
public ActionResult Example()
{
var model = new Example {
Text = "test"
};
return View(model);
}
Then the post back when the form is submitted
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Example(Example model)
{
model.Text += "a";
return View(model);
}
The view is as follows:
@model Stackoverflow.Example
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<h1>@Model.Text</h1>
@Html.EditorFor(model => model.Text);
<input type="submit" value="Save" />
}
When I first visit the page the heading and the text box have the same value
I press submit and the page loads again. The title has updated but the text box has the same value.
Why is the @Html.EditorFor(model => model.Text);
not getting the updated value?