asp.net - Passing Data From Controller to View MVC-5 -
i'm stuyding mvc-5 asp.net , following tutorial: https://www.youtube.com/watch?v=fu9v2midlta
i have created view , controller , therefore hello world display. i'm in part 2 of tutorial wherein i'm passing data controller view.
here codes:
home controller:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; namespace webapplication2.controllers { public class homecontroller : controller { // // get: /home/ public actionresult index() { return view(); } public actionresult showhome() { viewdata["currenttime"] = datetime.now.tostring(); return view("home"); } } } view:
@{ viewbag.title = "home"; } <html> <head> <title> welcome mvc 5 </title> <body> <div> homepage! <br/> time: <%= viewdata["currenttime"]%> </div> </body> </head> </html> the question is: why when type part: <% %>, ide not reading it? mean, speaker in tutorial using think visual studio 2013 ultimate. when types <% >%, there intellisense.
i'm using visual studio 2013 express web, when type
viewdata["currenttime"] = datetime.now.tostring(); the ide doesn't recognize , prints string. :(
glenn got confused between way on how code blocks annotated in aspx pages , how used in razor view engine nowadays.
you can see razor in action right @ top of view:
@{ viewbag.title = "home"; } and thats how it. curly braces optional, if use single expression, in case write
<div> homepage! <br/> time: @viewdata["currenttime"] </div> scott gu has written pretty article differences between 2 systems: http://weblogs.asp.net/scottgu/introducing-razor
as rule of thumb: if .aspx file, use <% %>. if .cshtml or .vbhtml use @{ }
Comments
Post a Comment