Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 31, 2012 10:33 PM by bruce (sqlwork.com)
Dec 30, 2012 08:27 PM|LINK
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:
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!
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.
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.