Convert razor to aspx in MVC3

2019-09-20 10:59发布

问题:

HI guys i have a razor file Index.cshtml which needs to be converted to aspx...can any one help me how to declare the classes and model every thing in .cshtml to .aspx

Here is my Index.cshtml code

Index.cshtml


@model  IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>
@{
    ViewBag.Title = "Projects";
}          

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            ProjectName
        </th>
        <th>
            Description     
        </th>
        <th>
            Status
        </th>
    </tr>

    @foreach (var item in Model)
    {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.projectName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.status)
        </td>       
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.projectName }) |
            @Html.ActionLink("Details", "Details", new { id = item.Description }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.status })
        </td>
    </tr>
    }
</table>

please can any one tell me how to write this code in aspx of MVC3

回答1:

anil,

it bugged me that you found this so difficult to do that i had to come back and give you the base details on how to do it yourself (teach a man to fish etc.. :-)). anyway, from the top, do the NORMAL stuff that aspx pages have, in your case:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>>" %>

ok, now onto a sample block:

razor:

@foreach (var item in Model)

aspx:

<% foreach (var item in Model) { %>
    //... stuff 
    <%: Html.DisplayFor(modelItem => item.Description) %>
    // more stuff
    <%: Html.ActionLink("Edit", "Edit", new { id = item.projectName }) %> |
    <%: Html.ActionLink("Details", "Details", new { id = item.Description })%> |
<% } %>

as you can see, purely syntax changes required that should take no more than 5 mins really.

Good luck -let me know how it all pans out.