Normally you return a View and either you leave it to a default name like in this case or pass in a particular view name and you can also pass in a viewmodel to it.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Normally you return a View and either you leave it to a default name like in this case or pass in a particular view name and you can also pass in a viewmodel to it.
Grz, Kris.
Actually , I am trying to pass the information of the ViewBag to a partial view that would be included in the layout of the site later, that's why i don't need the return View ( ) statement , in other words my objective is to pass data from a controller
action to the layout view and not a simple view of a single page !
Because the data is passed to the content view and that view is incorporated in the layout view, your values in your ViewData/ ViewBag should be accessible from the _layout page automatically.
(Please select 'Mark as Answer' if my response has helped you.)
Heythem
0 Points
6 Posts
Send data from controller to view ?
Dec 31, 2012 06:09 PM|LINK
Hello
I am developing an asp.net mvc web application, i added to a controller this code :
public ActionResult AdministrateurYes() { ViewBag.Display = "Administrateur"; return View(); }and i added a view to this method .
What i want to do is to use The viewBag to display data from the controller method without using the statement return View();
Is there a way to do that ?
Thanks
XIII
All-Star
182702 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: Send data from controller to view ?
Dec 31, 2012 06:20 PM|LINK
Hi,
Is there a specific reason why you ask this?
Normally you return a View and either you leave it to a default name like in this case or pass in a particular view name and you can also pass in a viewmodel to it.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Gaspard
Contributor
2066 Points
416 Posts
Re: Send data from controller to view ?
Dec 31, 2012 07:19 PM|LINK
At this web site,you can have more information regarding the controller and action Results
http://www.asp.net/mvc/tutorials/controllers-and-routing/aspnet-mvc-controllers-overview-cs
Regards
Heythem
0 Points
6 Posts
Re: Send data from controller to view ?
Dec 31, 2012 09:55 PM|LINK
Actually , I am trying to pass the information of the ViewBag to a partial view that would be included in the layout of the site later, that's why i don't need the return View ( ) statement , in other words my objective is to pass data from a controller action to the layout view and not a simple view of a single page !
calibur
Member
300 Points
124 Posts
Re: Send data from controller to view ?
Jan 01, 2013 11:59 AM|LINK
Because the data is passed to the content view and that view is incorporated in the layout view, your values in your ViewData/ ViewBag should be accessible from the _layout page automatically.
0ramramram0
Member
305 Points
73 Posts
Re: Send data from controller to view ?
Jan 01, 2013 01:27 PM|LINK
why you pass view data in controller to view.Its automatically get razor
use this line
@ViewData[ViewDataName"]