asp.net mvc3 razor语法转换

时间:2012-11-12 13:41:52

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

如何使用razor语法转换此gridview,我在其中有大括号(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>
      <% });%>

1 个答案:

答案 0 :(得分:0)

Razor仅使用<% ... %>符号替换括号@。例如,这一行

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

变为

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

基本上就是这样。您只需删除所有<% ... %>括号。