如何在Razor View Mvc中的If条件中使用Foreach循环? [英] How Can I Use Foreach Loop Inside The If Condition In Razor View Mvc?

查看:315
本文介绍了如何在Razor View Mvc中的If条件中使用Foreach循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆