将aspx视图迁移到Razor视图

时间:2011-03-23 13:48:43

标签: asp.net-mvc asp.net-mvc-3 razor

将mvc aspx视图迁移到Razor视图时遇到一些问题。什么是正确的Razor语法?非常感谢。

<%
    Html.Repeater<BoardViewModel>(
        Model.Boards, 
        "post", 
        "post", 
        (board, css) =>{%>

    <div class= "<% =css%>"> 
        <div class="post_title"><h2><% = Html.ActionLink(board.Name, "GetById", "Board", new {id=board.Id}, null) %></h2></div> 
        <div class="post_body"> 
            <p><% =board.Description%></p> 
        </div> 
    </div>
   <%}); %>

1 个答案:

答案 0 :(得分:0)

你可以简单地将其简化为以下(或类似的东西),而不必担心代表。在我看来更清洁。

@foreach(Board board in Model.Boards){
    <text>   
    <div class="post"> 

        <div class="post_title"><h2>@Html.ActionLink(board.Name, "GetById", "Board", new {id=board.Id}, null)</h2></div> 
        <div class="post_body"> 
            <p>@board.Description</p> 
        </div> 
    </div>