In the following 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()
,
But the code compiles without the "If" statement.For example
@{
WebGrid grid = new WebGrid(Model.SModel);
}
@grid.GetHtml().
What is the syntactical error in using If else statement
grid
isn't declared outside of the scope of your if
statment.
Try this instead:
@if (Model.SModel != null) {
WebGrid(Model.SModel).GetHtml()
}
I would try this:
@if (Model.SModel != null)
{
WebGrid grid = new WebGrid(Model.SModel);
grid.GetHtml()
}
else
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With