I'm working on a project which has BOTH WebForms code and MVC3 code. All Webforms code use a Site.Master page, which defines header, footer, Nav etc.
Some functions are added later, written in MVC. Currently they use "View/Shared/_layout.cshtml" by default. I want to use the same Site.Master page to "replace" or somehow work with the MVC code.
Then let's say you have a Razor Layout (Razor Layouts are like WebForms Masters) that reference to
the same three WebForm user controls.
_RazorLayout.cshtml: Lays out with the controls from above.
Page4.cshtml: Uses _RazorLayout.cshtml.
Page5.cshtml: Uses _RazorLayout.cshtml.
Page6.cshtml: Uses _RazorLayout.cshtml.
My problem is: currently my site.master page does NOT use any .ascx files (for header, footer seperately); everything is in 1 master page file. And I do not have an example of
how a _RazorLayout.cshtml uses .ascx files...
Can someone provide an example of how that works?
Also, my Nav bar in the Site.Master files has a code behind, where the "onCLick" functions are defined. Now with a "_RazorLayout.cshtml" file.... where does these log go? in the code behind of .ascx files?
Any help is appreciated!
Thanks,
Claudia
BTW - Scott also mentioned in his blog to use "Html.RenderPartial or Html.RenderAction " - which if someone can provide an example, I'd appreciate it very much as well.
only ascx files can be shared between webforms and razor. also note that in razor, each ascx will be hosted by its own empty page. move the navbar to a ascx that can be shared.
as MVC does not support any webform onclick handlers, you will need to move/copy the code behind to a controller. the MVC controller will not have access to any webform controls, only the post data. as the onclick handler was not in the page, you should
move the on click code to an controller action filter in MVC, and apply this filter to all actions that must support the ascx.
claudia888
Member
181 Points
434 Posts
How to use Site.Master with _layout.cshtml from Razor view?
Dec 30, 2012 08:27 PM|LINK
HI,
I'm working on a project which has BOTH WebForms code and MVC3 code. All Webforms code use a Site.Master page, which defines header, footer, Nav etc.
Some functions are added later, written in MVC. Currently they use "View/Shared/_layout.cshtml" by default. I want to use the same Site.Master page to "replace" or somehow work with the MVC code.
I searched around and read ScottHa's blog here:
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
He said:
Then let's say you have a Razor Layout (Razor Layouts are like WebForms Masters) that reference to the same three WebForm user controls.
My problem is: currently my site.master page does NOT use any .ascx files (for header, footer seperately); everything is in 1 master page file. And I do not have an example of how a _RazorLayout.cshtml uses .ascx files...
Can someone provide an example of how that works?
Also, my Nav bar in the Site.Master files has a code behind, where the "onCLick" functions are defined. Now with a "_RazorLayout.cshtml" file.... where does these log go? in the code behind of .ascx files?
Any help is appreciated!
Thanks,
Claudia
BTW - Scott also mentioned in his blog to use "Html.RenderPartial or Html.RenderAction " - which if someone can provide an example, I'd appreciate it very much as well.
bruce (sqlwo...
All-Star
36726 Points
5438 Posts
Re: How to use Site.Master with _layout.cshtml from Razor view?
Dec 31, 2012 10:33 PM|LINK
only ascx files can be shared between webforms and razor. also note that in razor, each ascx will be hosted by its own empty page. move the navbar to a ascx that can be shared.
as MVC does not support any webform onclick handlers, you will need to move/copy the code behind to a controller. the MVC controller will not have access to any webform controls, only the post data. as the onclick handler was not in the page, you should move the on click code to an controller action filter in MVC, and apply this filter to all actions that must support the ascx.