It is actually razor syntax to tell that we are starting to write c# code, if your don't put @ it will be considered as plain text so you need to put @ sign before writing c# code in the view and in html helper method you don't need to put semicolon in front of then it is razor syntax to write helpers this way.
For Example:
@Html.LabelFor(x=>m.SomeProperty) // here @ is telling that we are writing c# statement
When you write:
@if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.Partial("_SubLandingPage_List"); // this is wrong syntax
}
else
{
Html.Partial("_SubLandingPage_Grid");
}
the right way is to tell that this is a razor html helper and c# statement:
@if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
@Html.Partial("_SubLandingPage_List")
}
else
{
@Html.Partial("_SubLandingPage_Grid")
}
you can see more on razor syntax HERE
Few more links which will help you understanding razor:
http://www.asp.net/web-pages/tutorials/basics/2-introduction-to-asp-net-web-programming-using-the-razor-syntax
http://weblogs.asp.net/scottgu/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax
http://weblogs.asp.net/scottgu/introducing-razor
UPDATE:
An alternative can be to use RenderPartial which will work in the if statement without putting @ sign:
@if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.RenderPartial("_SubLandingPage_List");
}
else
{
Html.RenderPartial("_SubLandingPage_Grid");
}
For understanding Difference between Html.Partial
and Html.RenderPartial
, visist these links:
Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction
http://dotnethelpers.wordpress.com/2013/06/18/difference-between-html-renderpartial-vs-html-partial-and-html-renderaction-vs-html-action-in-mvc/
http://www.em64t.net/2010/12/razor-html-renderpartial-vs-html-partial-html-renderaction-vs-html-action-what-one-should-use/