I was trying a basic asp .net mvc project configuration explained below;
Before first submit, the result is left one in photo which is expected, after submit textbox(@Html.TextBoxFor(model => model.Name)
) and text(@Model.Name
) shows different values as seen in right one in photo, unexpectedly; why is it so? They show different values although their model is unique.
Model:
public class Personnel
{
public string Name { get; set; }
}
View:
@model deneme.Models.Personnel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Index", "Home"))
{
@Html.TextBoxFor(model => model.Name)
<br/>
<br/>
@Model.Name
<br/>
<br/>
<input type="submit" value="submit" />
}
Controller:
public ActionResult Index(Personnel personnel)
{
if (string.IsNullOrEmpty(personnel.Name))
{
personnel.Name = "Ahmet";
}
else
{
personnel.Name = personnel.Name + "server";
}
return View(personnel);
}