Интересно, почему я получаю нулевую модель, проходящую от представления к контроллеру.ASP MVC4 нулевая модель передана в действие в контроллере
Вот мой код в представлении (UpdatePersonal.cshtml):
@model Project.Models.UserInfo
@using (Html.BeginForm()){
@Html.LabelFor(m => m.userinfo.firstname);
@Html.TextBoxFor(m => m.userinfo.firstname, new { @Value = ViewBag.Firstname });
@Html.LabelFor(m => m.userinfo.lastname);
@Html.TextBoxFor(m => m.userinfo.lastname, new { @Value = ViewBag.Lastname });
@Html.LabelFor(m => m.userinfo.email);
@Html.TextBoxFor(m => m.userinfo.email, new { @Value = ViewBag.Email });
@Html.LabelFor(m => m.userinfo.phone);
@Html.TextBoxFor(m => m.userinfo.phone, new { @Value = ViewBag.Phone });
@Html.HiddenFor(m => m.username, new { @Value = ViewBag.Username });
<input type="submit" value="Submit" />}
Вот метод действия, который принимает его:
[HttpPost]
[AllowAnonymous]
public ActionResult UpdatePersonal(UserInfo userInfo){
//some code here
//my breakpoint}
я вижу модель передается имеет нулевое значение, я использовал точки останова
моя модель:
public class UserInfo
{
[BsonId]
public string username { get; set; }
public Info userinfo { get; set; }
public Address address { get; set; }
public class Info
{
public string firstname { get; set; }
public string lastname { get; set; }
public string email { get; set; }
public string phone { get; set; }
}
public class Address
{
public string street { get; set; }
public string address1 { get; set; }
public string address2 { get; set; }
public string postalcode { get; set; }
public string country { get; set; }
}
}
Ваше действие украшено '[HttpPost]'? – Jonesopolis
Да, у меня есть [HttpPost] в действии –
Как выглядит ваша модель? – beautifulcoder