FloatLeft
FloatLeft

Reputation: 1337

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?

Upvotes: 3

Views: 2641

Answers (1)

Timothy Strimple
Timothy Strimple

Reputation: 23060

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.

Upvotes: 4

Related Questions