Asp.Net MVC:在@Html:Grid中使用HTML标记

问题描述

|| 是否可以在@ Html.Grid中使用内联HTML(我正在尝试在其中一列中创建超链接标记)。这是一个例子:
@model Example.Models.ExampleItems

@{
    ViewBag.Title = \"Example Items\";
}

<div id=\"ExampleContentInnerContainer\">
<h2>Example Items</h2>

<div id=\"ExampleListGrid\">
    <span class=\"ExampleGrid\">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? \"Yes\" : \"No\").Named(\"Mandatory\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateRequested)).Named(\"Date Requested\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateDeadline)).Named(\"Deadline Date\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateReceived)).Named(\"Date Received\");         
            c.For(a => a.Comment).Named(\"Comment\");
            c.For(a => a.Name).Named(\"Checklist type\");
            c.For(a => @:<a href=\"www.google.com\" />);
        }
        )
    </p>
    </span>
</div>
任何帮助都将受到欢迎。 UPDATE-根据archil的帖子,我的新代码变为:
@model Example.Models.ExampleItems

@{
    ViewBag.Title = \"Example Items\";

    Func<dynamic,object> updateLink = @<a href=\"#?w=500\" rel=\"Checklist_Popup\" class=\"poplight\">@item</a>;
}

<div id=\"ExampleContentInnerContainer\">
<h2>Example Items</h2>

<div id=\"ExampleListGrid\">
    <span class=\"ExampleGrid\">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? \"Yes\" : \"No\").Named(\"Mandatory\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateReceived)).Named(\"Date Received\");         
            c.For(a => a.Comment).Named(\"Comment\");
            c.For(a => a.Name).Named(\"Checklist type\");
            c.For(a => updateLink(\"Update\"));        
        }
        )
    </p>
    </span>
</div>
    

解决方法

看一下模板化的剃刀代表。在那里您可以进行链接生成     ,您可以尝试将\“ ... \”包装在\“ @ ... \”标记中。 在您的情况下,它看起来像这样:
@model Example.Models.ExampleItems

@{
    ViewBag.Title = \"Example Items\";
}

<div id=\"ExampleContentInnerContainer\">
<h2>Example Items</h2>

<div id=\"ExampleListGrid\">
    <span class=\"ExampleGrid\">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? \"Yes\" : \"No\").Named(\"Mandatory\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateRequested)).Named(\"Date Requested\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateDeadline)).Named(\"Deadline Date\");
            c.For(a => string.Format(\"{0:dd/MM/yyyy}\",a.DateReceived)).Named(\"Date Received\");         
            c.For(a => a.Comment).Named(\"Comment\");
            c.For(a => a.Name).Named(\"Checklist type\");
            c.For(a => @<text><a href=\"www.google.com\" /></text>);
        }
        )
    </p>
    </span>
</div>
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...