【问题标题】:Convert razor to aspx in MVC3在MVC3中将剃刀转换为aspx
【发布时间】:2012-07-13 07:23:23
【问题描述】:

大家好,我有一个剃须刀文件 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>

谁能告诉我如何用MVC3的aspx编写这段代码

【问题讨论】:

  • @jimtollan 我做到了,我在 >" %> 说 foreach 表达式无效..

标签: asp.net-mvc-3 c#-4.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 分钟。

祝你好运 - 让我知道结果如何。

【讨论】:

    猜你喜欢
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多