简体   繁体   中英

Converting MVC Site master page to Razor layout page - what to do with codebehind?

I've been trying to convert my site that currently uses .aspx view pages to Razor. Everything works fine except I'm stumped on how to deal with the code behind on the master page.

I have some code in the "OnInit" event and don't know where to put it now.

Any ideas?

You could use the _ViewStart.cshtml razor page. It will execute before every view is rendered.

Depending on what you're trying to do you could also create a ActionFilterAttribute for your controller which will execute a method before rendering the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM