ASP.Net MVC 2 - Code for master page

551 views Asked by At

I am newbie in MVC and trying to create application in asp.net mvc2. For the common header and footer i wants to use master pages which are having dynamic content, Can anyone please tell me where is the best place to write code for master page. I am trying to add code behind for master page but I am not sure about what is recommended in this situation.

1

There are 1 answers

1
SoftSan On

In my opinion, you can create partial views (type of user control) and render it in your master page. Write all the logic to get data from database into partial view's action method. You can write action method in any of your controller. ex. You can create a Layout controller and write action method related to master page. A partial view can also be reusable.

To render your partial view in master page you can write code like :

<div><%= Html.Action("Header", "Layout") %></div>