I would like to clarify one thing about MVC5 Razor Views.
I was told that I don't have to use HTML Helpers (@Html.EditorFor, @Html.TextBoxFor) in my razor views and it will still work.
Controller Code
[HttpPost]
public ActionResult Create(Models.TestObj obj)
{
ViewBag.TestStr = string.Format("You typed: {0} {1}", obj.FirstName, obj.LastName);
return View(obj);
}
Razor View
@using (Html.BeginForm())
{
<div>
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control", style = "width: 120px;" } })
<input class="form-control text-box single-line" id="LastName" name="LastName" style="width: 120px;" type="text">
<input type="submit" name="submit" value="Filter" / >
</div>
@ViewBag.TestStr
}
But when I actually test it like the above, the value typed in 'LastName' textbox is not preserved. I can catch both textbox values in my Controller. But after postback, lost the value in 'LastName' textbox. The textbox which is created by using HTMLHelper didn't lose the value though.
Am I doing something wrong or is it supposed to be like that? Do I have to use HtmlHelpers in RazorViews in MVC5 if I want to keep the submitted values?