【问题标题】:asp.net mvc3 razor syntax convertasp.net mvc3 razor 语法转换
【发布时间】:2012-11-12 13:41:51
【问题描述】:

如何在剃刀语法中转换此网格视图,我有大括号 (data => { %>) ?

<%Html.GridView<Employee>(
      Model,
      data => { %>
        <table class="grid" cellpadding="0" cellspacing="0">
            <tr>
                <th>&nbsp;</th>
                <th>&nbsp;</td>
                <th>&nbsp;</td>
                <th>Name</th>
                <th>E-mail</th>
            </tr>
      <% },
      (item, css) => { %>
        <tr class="<%=css%>">
            <td><%=Html.ActionImage("Edit", "Home", new { Id = item.Id }, "~/Content/edit.gif", "Edit")%></td>
            <td><%=Html.ActionImage("Delete", "Home", new { Id = item.Id }, "~/Content/delete.gif", "Delete")%></td>
            <td>&nbsp;</td>
            <td><%=item.Name%></td>
            <td><%=item.Email%></td>
        </tr>
      <% },
      "item",
      "item-alternating",
      item => { %>
        <%using (Html.BeginForm("Save", "Home", new { Id = item.Id }, FormMethod.Post, new { id = "editForm" })) {%>
            <tr class="item-edit">
                <td><input type="image" runat="server" id="save" src="~/Content/ok.gif" alt="Update" /></td>
                <td><%=Html.ActionImage("Index", "Home", null, "~/Content/cancel.gif", "Cancel")%></td>
                <td>&nbsp;</td>
                <td><%=Html.TextBox("Name", item.Name)%></td>
                <td><%=Html.TextBox("Email", item.Email)%></td>
            </tr>
        <% } %>
      <% },
      data => { %> 
            <tr>
                <td colspan="5"><hr /></td>
            </tr>       
            <tr class="paging">      
                <td colspan="5">
                    <% if (data.PagedList.IsPreviousPage) { %>
                        <%=Html.ActionImage("Show", "Home", new { page = data.PagedList.PageIndex - 1 }, "~/Content/previous.gif", "Previous page")%>
                    <% } %>

                    <%=data.PagedList.TotalCount.ToString()%> records

                    <% if (data.PagedList.IsNextPage) { %>
                        <%=Html.ActionImage("Show", "Home", new { page = data.PagedList.PageIndex + 1 }, "~/Content/next.gif", "Next page")%>
                    <% } %>
                </td>
            </tr>  
            <tr>
                <td colspan="5">&nbsp;</td>
            </tr>
            <%using (Html.BeginForm("Add", "Home", FormMethod.Post, new { id = "addForm" })) {%>
                <tr>
                    <th>&nbsp;</th>
                    <th>&nbsp;</td>
                    <th>&nbsp;</td>
                    <th>Name</th>
                    <th>E-mail</th>
                </tr>
                <tr>
                    <td><input type="image" runat="server" id="add" src="~/Content/add.gif" alt="Add" /></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td><%=Html.TextBox("Name", "")%></td>
                    <td><%=Html.TextBox("Email", "")%></td>
                </tr>
            <% } %>  
            </tr>
        </table>
      <% });%>

【问题讨论】:

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


    【解决方案1】:

    Razor 仅将括号 &lt;% ... %&gt; 替换为 @ 符号。例如,这一行

    <%=Html.TextBox("Email", "")%>
    

    变成

    @Html.TextBox("Email", "")
    

    基本上就是这样。您只需删除所有 &lt;% ... %&gt; 括号。

    【讨论】:

      猜你喜欢
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多