问题描述
||
是否可以在@ 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>
解决方法
看一下模板化的剃刀代表。在那里您可以进行链接生成
,您可以尝试将\“ ... \”包装在\“ @ ... text> \”标记中。
在您的情况下,它看起来像这样:
@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>