Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 03, 2012 05:52 PM by JLPingree
Member
26 Points
8 Posts
Aug 02, 2012 05:28 PM|LINK
I am just starting my journey from ASPX web Forms to MVC 4. In testing I have found the following and I want to understand why...
This works in my _Layout.cshtml =>
@Scripts.Render( @ViewBag.JQuery ) @Scripts.Render( @ViewBag.Scripts )
However this does not:
@{ if (ViewBag.JQuery != null) { Scripts.Render(ViewBag.JQuery); } if (ViewBag.Scripts != null) { Scripts.Render(ViewBag.Scripts); } }
All I need is a brief explination, thanks.
All-Star
27438 Points
4893 Posts
MVP
Aug 02, 2012 10:23 PM|LINK
Once you're in code-mode in razor, you need an @ prefixing an expression to render it. Otherwise it's just returning the rendered html and nobody is using it.
So:
@if(..)
{
// C# code-mode
@Scripts.Render(...);
}
Aug 03, 2012 05:52 PM|LINK
Many thanks.
JLPingree
Member
26 Points
8 Posts
_Layout.cshtml
Aug 02, 2012 05:28 PM|LINK
I am just starting my journey from ASPX web Forms to MVC 4. In testing I have found the following and I want to understand why...
This works in my _Layout.cshtml =>
However this does not:
@{ if (ViewBag.JQuery != null) { Scripts.Render(ViewBag.JQuery); } if (ViewBag.Scripts != null) { Scripts.Render(ViewBag.Scripts); } }All I need is a brief explination, thanks.
BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: _Layout.cshtml
Aug 02, 2012 10:23 PM|LINK
Once you're in code-mode in razor, you need an @ prefixing an expression to render it. Otherwise it's just returning the rendered html and nobody is using it.
So:
@if(..)
{
// C# code-mode
@Scripts.Render(...);
}
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
JLPingree
Member
26 Points
8 Posts
Re: _Layout.cshtml
Aug 03, 2012 05:52 PM|LINK
Many thanks.