ASp.Net MVC中的分析器错误 [英] Parser Error in ASp.Net MVC
本文介绍了ASp.Net MVC中的分析器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在MVC中做了一个简单的页面,我收到了解析器的错误。我的代码很好。我只需要一个会导致这个错误的东西。
控制器:HomeController
I just did a simple Page in MVC where i was getting an error of parser. My code was everything fine. i just need some one what would cause this error.
Controller:HomeController
public ActionResult Index()
{
ViewBag.Countries = new List<string>()
{
"India",
"Japan",
"UK",
"USA"
};
return View();
}
我的观点:Index.cshtml
My View:Index.cshtml
<h2>Countries List</h2>
<ul>
@foreach (string strCountry in ViewBag.Countries)
<li>
@strCountry
</li>
</ul>
我的错误显示为:
解析器错误消息:预期为{但找到<。块语句必须用{和}括起来。您不能在CSHTML页面中使用单语句控制流语句。例如,不允许以下内容:
推荐答案
@foreach (string strCountry in ViewBag.Countries){
<li>
@strCountry
</li>
}
亲爱的尝试。
这样就可以了。因为你正在使用应该有一个开始和关闭括号的循环。
类似于服务器端代码。
我希望这样做。
发布如果有的话,请回复你的查询。
谢谢。:)
Try with this dear.
This will work out. As you are using loop that should have a start and close brackets.
Similar to server side code.
I hope this works.
Post back your queries if any.
Thanks.:)
<h2>Countries List</h2>
<ul>
@{
foreach (string strCountry in ViewBag.Countries)
<li>
@strCountry
</li>
}
</ul>
我认为上面的代码将是你的
这篇关于ASp.Net MVC中的分析器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文