如何在MVC5中設置包含列表的ViewBag中的TextBox值?正如你可以看到我的名單是在Viewbag.photos,我想有photo.id在我的文本框,然後傳遞的每個值給控制器從MVC5中的ViewBag列表中設置TextBox值C#
@foreach (var photo in ViewBag.photos)
{
@if (@photo.comment != null)
{
<h6>@photo.comment</h6>
}
else
{
<h6> - </h6>
}
@Html.TextBox("photoID", @photo.id)
}
嘗試這樣做,我收到一個錯誤:
Error CS1973 'HtmlHelper>' has no applicable method named 'TextBox' but appears to have an extension method by that name. Extension methods cannot be dinamically dispached.
也許還有另一種解決方法?
請製作ViewModel並傳入,而不是使用ViewBag ... – Milney