опробовал ваше решение на следующем источнике, и он отлично работает для меня.
Модель
public class LocationViewModel
{
private string _location = "test";
public string Location
{
get { return _location; }
set { _location = value; }
}
}
Действие
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View(new LocationViewModel());
}
Просмотр
@model LocationViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Test</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Location)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Location)
@Html.ValidationMessageFor(model => model.Location)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>