@{
Layout = null;
Dictionary<string, string> Nav = ViewData["Nav"] as Dictionary<string, string>;
}
@{
if(Nav!=null){
Nav.Each(p =>
{
@<a>123</a>
});
}
}
就这么一段,缺分号CS1002: ; expected。求助。折腾死人了。
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1002: ; expected
Source Error:
Line 8: { |
Source File: d:\GIT\review.vancl.com\Vancl.Review.Com.Web\Vancl.Review.Com.Web\Views\Review\Nav.cshtml Line: 10
http://stackoverflow.com/questions/9393074/how-to-use-lamda-in-mvc-3-razor
这个才是答案。唉
if(Nav!=null){
foreach(var item in Nav)
{
<a>@item.Value</a>
}
}
推荐一篇文章:asp.net mvc3 Razor引擎中@使用规则小记
不能用lamda这种吗?foreach不大好看
@调调儿: Dictionary貌似没有Each方法吧
@artwl: 自己写的。这个不是问题。可以当作一个List的ForEach方法
@调调儿: 哦,肯定是可以用lamda的,你把我推荐的那篇文章好好看看应该就会了