我得到了一个包含Person和Address的实体类。JSON将数据发布到mvc控制器
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Address> Addresses { get; set; }
}
public class Address
{
public string ZipCode { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
在我看来,我显示了一些复选框。
@model DataContext.Models.Persons
@{
ViewBag.Title = "Person list";
}
@using (Html.BeginForm("Update", "Test", FormMethod.Post))
{
<div id="personContainer">
@foreach(var t in Model.Person)
{
<input type="checkbox" value="@t.ID" name="@t.FirstName ">@t.FirstName <br />
}
</div>
<p>
<input type="submit" id="save">
</p>
}
我的控制器看起来是这样的:
[HttpPost]
public JsonResult Update(Person p)
{
return Json(new { redirectTo = Url.Action("Index") });
}
我要发布的数据必须是强类型。 如何将数据(在本例中为所有复选框)回传到使用JSON的'更新'控制器?
是有什么可以帮助我解决这个问题吗? – Yustme