Razor 中的 MVC2 代码转换
我正在使用某人的代码进行分页。他的代码位于 MVC 2 中,我希望它位于 MVC3 Razor 中。问题出在语法上。
下面是 mvc 中的代码,需要有人修复 razor 的语法。
问题出在这一行
IList<Customer> customers = (IList<Customer>)Model.Data;
//不能直接使用Model.Data。不选择泛型类型。
IList<Customer> customers = (IList<Customer>)Model.Data;
foreach (Customer item in customers) { %>
<tr onclick="onRowClick(<%= item.ID %>)">
<td>
<%= Html.ActionLink("Edit", "Edit", new { id=item.ID}) %> |
<%= Html.ActionLink("Delete", "Delete", new { id=item.ID })%>
</td>
<td>
<%= Html.Encode(item.ID) %>
</td>
<td>
<%= Html.Encode(item.FirstName) %>
</td>
</tr>
<% } %>
I am using someones code for paging. His code is in MVC 2 and I want it in MVC3 Razor. Problem is with syntax.
Below is the code in mvc need someone to fix syntax for razor please.
Problem is in this line
IList<Customer> customers = (IList<Customer>)Model.Data;
//Can't use Model.Data directly. Doesn't pick up generic type.
IList<Customer> customers = (IList<Customer>)Model.Data;
foreach (Customer item in customers) { %>
<tr onclick="onRowClick(<%= item.ID %>)">
<td>
<%= Html.ActionLink("Edit", "Edit", new { id=item.ID}) %> |
<%= Html.ActionLink("Delete", "Delete", new { id=item.ID })%>
</td>
<td>
<%= Html.Encode(item.ID) %>
</td>
<td>
<%= Html.Encode(item.FirstName) %>
</td>
</tr>
<% } %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该行可以这样翻译:
然后:
我也将从这次迁移中受益,以改进此代码。目前,您在视图中使用的循环很丑陋,可以用显示模板替换。
因此,在您的主视图中:
以及在
~/Views/Home/DisplayTemplates/Customer.cshtml
中:The line could be translated like this:
and then:
I would also benefit from this migration to improve this code. Currently you are using loops in your views which are ugly and could be replaced with display templates.
So, in your main view:
and in
~/Views/Home/DisplayTemplates/Customer.cshtml
: