Conditional section syntaxe with razor asp.net mvc3?

Up vote 0 down vote favorite share g+ share fb share tw.

I'm not really familiar with the razor view engine. So, I have a problem with the syntaxe. I have "_layout.

Cshtml" : @if (IsSectionDefined("Slideshow")) { @RenderSection("Slideshow"); } else { blah blah blah } And then, in the "default. Cshtml" @if(@ViewBag. Article == null) { blabla } else { @section Slideshow { slide here } } So, here is my problem : If I let the @ before section, I have an error line:27 telling me that I don't have to keep the @ inside a @if statement : "Mot clé "section" inattendu après le caractère "@".

Une fois à l'intérieur du code, vous n'avez pas besoin de préfixer des constructions telles que "section" avec "@". " If I don't let the @ before section, I have an errorline:29 2 lines after (...) telling me a } is missing. CS1513: } attendue So, I guess it is possible to do but I don't know how to do it.

Could you help me please. Thanks asp.net asp.net-mvc asp.net-mvc-3 razor link|improve this question asked Nov 25 '11 at 10:34Netah397 57% accept rate.

This should compile: @if (IsSectionDefined("Slideshow")) { RenderSection("Slideshow"); } else { @:blah blah blah } @if(ViewBag. Article == null) { @:blabla } else { section Slideshow { @:slide here } } You need to start a c# statement with a @ only if the compiler doesn't know you want to write actual code. Using @: at the start of plain text, the compiler knows its plain text.

Using tags to enclose text has the same effect. Every c# statement inside tag needs to start with a.

You can do like this, @{ if(ViewBag. Article == null) { blabla } else { section Slideshow { slide here } } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions