When I set ViewBag.Title
at the top of a Razor template, the Model.Title
editor template text box is populated using the value of ViewBag.Title
instead of the expected Model.Title
value. Calling Html.EditorFor(x => Model.Title)
explicitly does not produce this behaviour.
How do I prevent my editor template from showing the ViewBag.Title
value without maintaining a custom editor template for my model?
Code
@{
ViewBag.Title = "Edit Post " + Model.Title;
}
@Html.EditorFor(x => Model.Title) @* renders "My Title" text box *@
@Html.EditorFor(x => Model) @* renders "Edit Post My Title" text box *@