简体   繁体   中英

asp.net mvc3 razor syntax convert

How do I convert this gridview in razor syntax, I have curly brackets inside (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>
      <% });%>

Razor replaces the brackets <% ... %> with just the @ symbol. So for example, this line

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

becomes

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

That's basically it. You'll just have to remove ALL of the <% ... %> brackets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM