I have tried all solution proposed to other, similar questions but none of them seems to work. In essence I am trying to display a table filled with data from collection of models. That in itself is not a problem, however I would like to force razor to generate it always in 3 columns (no matter how many elements we have). My original idea was to do it that way:
<table class="projects-grid">
<tr>
@for(int i = 0; i< Model.Count(); i++)
{
if (i != 0 && i % 3 == 0)
{
Html.Raw("</tr><tr>");
}
var item = Model.ElementAt(i);
<td class="project-tile">
@Html.DisplayFor(modelItem => item.Title)
</td>
}
</tr>
</table>
So in essence every third element I would like Razor to output "" string to add another row to the table. All seems to work fine other than this sting is not present in page source. In debug I can see that this line
Html.Raw("</tr><tr>");
Is actually called, but no output in generated page is present.
Any help? Many thanks in advance....
Answers
7
|
The reason it's not outputing is because of the context of the razor syntax being executed. In your
Returns an
|
@Html.Raw("<div style='c olor:red'>输出字 符串</div>")
结果: 输出字符串
比如有个字符串是这样的<font color='red'>红字</font>
如果是用@Html.Raw('<font color='red'>红字</font>'),就会显示出红色的”红字“,不用的话会直接显示这段html字符串(<font color='red'>红色文字</font>)
我遇到的问题是:
我在后台定义了一个变量 string a="<div><input type="text" value="你好" /></div>";
然后在js 里写
var strHtml='@a';
$("#ruleDetaile").append(strHtml);
结果显示处理的是:<div><input type="text" value="你好" /></div>。而我想好的效果是:一个文本框里写着你好
百思不得其解 然后问了我老大 他改成了:var strHtml='@Html.Raw(a)'; 这样就可以了