模型
public class PdfPage
{
public IEnumerable<PdfPhoto> Photos { get; set; }
}
public class PdfPhoto
{
public string path { get; set; }
}
看法
<ul>
<li>
<%= Html.Hidden("ListPages[0].Photos[0].path", "/public/pdfMaker/4_e.jpg")%>
<%= Html.Hidden("ListPages[0].Photos[1].path", "/public/pdfMaker/4_f.jpg")%>
<%= Html.Hidden("ListPages[0].Photos[2].path", "/public/pdfMaker/13_p.jpg")%>
</li>
<li>
<%= Html.Hidden("ListPages[1].Photos[0].path", "/public/pdfMaker/5_f.jpg")%>
<%= Html.Hidden("ListPages[1].Photos[1].path", "/public/pdfMaker/7_f.jpg")%>
<%= Html.Hidden("ListPages[1].Photos[2].path", "/public/pdfMaker/8_e.jpg")%>
<%= Html.Hidden("ListPages[1].Photos[3].path", "/public/pdfMaker/8_f.jpg")%>
</li>
<li>
<%= Html.Hidden("ListPages[2].Photos[0].path", "/public/pdfMaker/11_e.jpg")%>
</li>
</ul>
控制器
public ActionResult Create(List<PaginaPdf> ListPages)
{
string list = string.Empty;
foreach (var page in ListPages)
foreach(var photo in page.Photos)
list += "photo: " + photo .path + "\r\n";
return new ContentResult
{
Content = list
};
}
但不起作用。
有谁知道如何在 MVC 2 中绑定嵌套列表?