Agreed with CodeHobo ... the classic syntax (<% %>) can still be used but razor just types a bit faster... as said in the previous post, make sure your html is xhtml compliant though as it should be or you'll run in to problems..
What is the meaning of @ and { } in view of MVC. I do this means server side code is exceuted ? Cane i nest to any other leavels also ?
as nobody here answered this easy question good here it is...
in view you got 3 possibilities in razor
@{
ViewBag.Test = "blabla"
<span>ViewBag.Test</span>
} // you use this to make some code in the view you can render parts by using html tags
@ViewBag.Test // the normal way of showing something in html
@(ViewBag.Test + " toedoeloe") // another way if you have to do calculations and show them after
i hope this gives you some information on what is what and how to use
rock_420
Member
25 Points
14 Posts
what is @ { }
Sep 11, 2012 02:34 PM|LINK
What is the meaning of @ and { } in view of MVC. I do this means server side code is exceuted ? Cane i nest to any other leavels also ?
interwandere...
Contributor
2693 Points
542 Posts
Re: what is @ { }
Sep 11, 2012 02:40 PM|LINK
To answer your question in short : yes
this syntax allows you to write code faster... Just make sure your html is xhtml compliant.
.one of my (older) projects social tomorrow and
craigber
Member
29 Points
22 Posts
Re: what is @ { }
Sep 11, 2012 04:08 PM|LINK
No, it isn't server side code. That's Razor syntax. It lets you embed C# code that's then run before sending the web page to the browser. See http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
CodeHobo
All-Star
18647 Points
2647 Posts
Re: what is @ { }
Sep 11, 2012 05:19 PM|LINK
Razor syntax is server side code. Razor is a view engine and any code enclosed in the @ { } is executed server side.
Blog | Twitter : @Hattan
interwandere...
Contributor
2693 Points
542 Posts
Re: what is @ { }
Sep 11, 2012 08:10 PM|LINK
Agreed with CodeHobo ... the classic syntax (<% %>) can still be used but razor just types a bit faster... as said in the previous post, make sure your html is xhtml compliant though as it should be or you'll run in to problems..
.one of my (older) projects social tomorrow and
craigber
Member
29 Points
22 Posts
Re: what is @ { }
Sep 11, 2012 08:48 PM|LINK
ACK! That's what I get for being half-asleep when I reply. Yes, I knew it is server side code, but read it client side. Sorry for any confusion.
sp00k
Participant
1916 Points
435 Posts
Re: what is @ { }
Sep 12, 2012 09:41 AM|LINK
as nobody here answered this easy question good here it is...
in view you got 3 possibilities in razor
@{ ViewBag.Test = "blabla" <span>ViewBag.Test</span> } // you use this to make some code in the view you can render parts by using html tags @ViewBag.Test // the normal way of showing something in html @(ViewBag.Test + " toedoeloe") // another way if you have to do calculations and show them afteri hope this gives you some information on what is what and how to use
ossprologix
Member
392 Points
127 Posts
Re: what is @ { }
Sep 12, 2012 12:00 PM|LINK
use @ for variable
use @{ } for code block
@{ if(...) foreach(...) var text = 'hello code block'; }hope this helps
:)
Yanping Wang...
Star
14863 Points
1527 Posts
Microsoft
Re: what is @ { }
Sep 13, 2012 10:25 AM|LINK
You should learn razor first:http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3razor.aspx
Feedback to us
Develop and promote your apps in Windows Store