我新的MVC 3,並有這個問題入手,@foreach環3
我有一個類定義爲
Class abc
{ public string Id { get; set; }
public string str1 { get; set; }
public string Action { get; set; }
public string Name { get; set; }
public string Title {get; set;}
}
我MVC2的aspx的ViewPage,我就是用這個ABC類爲模型,並有這個代碼
<%
Model.ForEach(a =>
{ %>
<%= Html.ActionLink(a.Title ,
a.Action , // <-- ActionMethod
a.Name , // <-- Controller Name.
new { key = a.Id }, // <-- Route arguments.
new { title = a.str1 })%>
<br /><br />
<% }); %>
可以請你幫我這一段代碼轉換爲MVC Razor視圖?, @model ABC
<%
Model.ForEach(a =>
{ %>
<%= Html.ActionLink(a.Title ,
a.Action , // <-- ActionMethod
a.Name , // <-- Controller Name.
new { key = a.Id }, // <-- Route arguments.
new { title = a.str1 })%>
<br /><br />
<% }); %>
當我嘗試使用@foreach(模型中的var abc)時,我得到錯誤消息,需要實現Ienumerable?如何使用@for實現請幫助或給我指針。謝謝