在MVC的Razor视图使用if语句 [英] Using If statement in a MVC Razor View
本文介绍了在MVC的Razor视图使用if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下code,
如果我使用@If的声明,我得到下面的编译code误差这个名字网格在目前情况下不存在。
If I use "@If" statement ,I get the following compile code error as " The name 'grid' does not exist in the current context.
@if (Model.SModel != null)
{
@{
WebGrid grid = new WebGrid(Model.SModel);
}
}
else
{
}
@grid.GetHtml()
不过,code编译没有如果statement.For例如
But the code compiles without the "If" statement.For example
@{
WebGrid grid = new WebGrid(Model.SModel);
}
@grid.GetHtml().
什么是用语法错误如果else语句
What is the syntactical error in using If else statement
推荐答案
电网
是不是如果宣告你的的范围之外code>说明书。
grid
isn't declared outside of the scope of your if
statment.
试试这个:
@if (Model.SModel != null) {
WebGrid(Model.SModel).GetHtml()
}
这篇关于在MVC的Razor视图使用if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文