在MVC3中将razor转换为aspx

时间:2012-07-13 07:23:24

标签: asp.net-mvc-3 c#-4.0

我们有一个razor文件Index.cshtml需要转换为aspx ...任何人都可以帮助我如何声明类和.cshtml中的所有东西到.aspx

这是我的Index.cshtml代码

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>

请任何人告诉我如何在MVC的aspx中编写此代码

1 个答案:

答案 0 :(得分:1)

阿尼尔,

它告诉我你发现这很难做到,我不得不回来给你自己如何做的基本细节(教一个人钓鱼等...... :-))。无论如何,从上到下,执行aspx页面的NORMAL内容,在您的情况下:

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

好的,现在进入样本区:

剃刀:

@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 })%> |
<% } %>

正如您所看到的,纯粹需要进行语法更改,实际上不应超过5分钟。

祝你好运 - 我知道这一切是怎么回事。