У меня есть следующий ViewModel:модели имена из ViewModel в бритве
public class ProfileViewModel
{
public BandProfileModel BandProfile { get; set; }
public MusicanProfileModel MusicianProfile { get; set; }
public RegularProfileModel RegularProfile { get; set; }
}
Im помощью этой ViewModel На мой взгляд, чтобы разместить форму:
@using (Ajax.BeginForm("RegisterBand", "NewProfile", new AjaxOptions() { HttpMethod = "Post",
InsertionMode = InsertionMode.Replace
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-10">
Bandname
</div>
<div class="col-md-10">
@Html.EditorFor(x => x.BandProfile.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(x => x.BandProfile.Name, "", new { @class = "text-danger" })
</div>
</div>
Вот моя RegisterBand модель:
public ActionResult RegisterBand(BandProfileModel model)
{
if (ModelState.IsValid == false)
{
return Json(JsonRequestBehavior.AllowGet);
}
return View("Index");
}
Проблема, которую я имею, заключается в том, что атрибут name полей ввода - это BandProfile.Name, BandProfile.Genre, а не только G enre и Name.
Как я могу решить эту проблему?
В дополнение к принятым ответ, вы также можете использовать 'общественного ActionResult RegisterBand ([Bind (Ptefix =«BandProfile ")] BandProfileModel model)', который эффективно перекрывает префикс при связывании –