如何在Razor View Mvc中的If条件中使用Foreach循环? [英] How Can I Use Foreach Loop Inside The If Condition In Razor View Mvc?
问题描述
@if(@ Html.Raw(@ViewData [Message])== null)
{
foreach( ViewBag.Fnames中的var c)
{
// i = i + 1;
// string str =categories;
// str = str + i;
< label class =checkbox>
< input type =checkboxname = sid值= c> @c
< / label>
}
} < br $>
其他
{
@ Html.Raw(@ViewData [留言])
}
///////////////////////////////////////// ///////////////////////////////////////
我必须使用上面的代码但是foreach循环没有正常工作.......
@if (@Html.Raw(@ViewData["Message"]) == null)
{
foreach (var c in ViewBag.Fnames)
{
//i = i + 1;
//string str = "categories";
//str = str + i;
<label class="checkbox">
<input type="checkbox" name=sid value=c > @c
</label>
}
}
else
{
@Html.Raw(@ViewData["Message"])
}
////////////////////////////////////////////////////////////////////////////////
I have to use the above code But the foreach loop does'nt work propperly.......
推荐答案
这篇关于如何在Razor View Mvc中的If条件中使用Foreach循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!