我得到了一個包含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