1

How do you guys update (let's say) two partials in a controller action going to the View? For example, you have a left nav partial for links and on the right is your main content. Your main content has a ViewModel that it binds to. Do you guys have a seperate ViewModel for your nav page? If so, do you then create a bigger ViewModel each time that has the main content view model and the left nav ViewModel?

RailRhoad
  • 2,128
  • 2
  • 25
  • 39
  • possible duplicate of [How to create a strongly typed master page using a base controller in ASP.NET MVC](http://stackoverflow.com/questions/768236/how-to-create-a-strongly-typed-master-page-using-a-base-controller-in-asp-net-mvc) – jscs Sep 27 '11 at 04:19

3 Answers3

0

I would have one ViewModel for the nav page (e.g. CategoryListViewModel) and one for the content page (e.g. ProductListViewModel). Then load the CategoryListViewModel in a base controller:


public abstract class BaseController : Controller
{
    var _categoryRepository = new CategoryRepository();

    protected BaseController()
    {
        ViewData["Categories"] = _categoryRepository.GetCategories();
    }
}

public class ProductsController : BaseController
{
    var _productRepository = new ProductRepository();

    public ActionResult Index()
    {
        return View(_productRepository.GetProducts());
    }
}

and then in the MasterPage read the categories from the ViewData, and in the content page read the products from the Model on the ViewPage.

Ole Lynge
  • 4,457
  • 8
  • 43
  • 57
0

You can break the page into different independent sections, have a look at this page here. Here you have to use Html.RenderAction() for which you have to download the ASP.NET MVC Futures assembly from codeplex.

San
  • 2,316
  • 4
  • 26
  • 35
-1

Actually I was eventually eluding to this solution. Thanks guys for your input!

Community
  • 1
  • 1
RailRhoad
  • 2,128
  • 2
  • 25
  • 39