将列表与嵌套列表绑定
模型
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 中绑定嵌套列表?
Model
public class PdfPage
{
public IEnumerable<PdfPhoto> Photos { get; set; }
}
public class PdfPhoto
{
public string path { get; set; }
}
View
<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>
Controller
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
};
}
but doesn't work.
Does anyone know how to bind a nested list in MVC 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,它有效。
我错过了视图中的“s”。
我的错误。
Sorry, it works.
I miss a "s" in View.
My mistake.