tags:

views:

101

answers:

3

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?

A: 

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
A: 

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
A: 

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

RailRhoad
Do not post comments as answer. And accept the one that helped.
Arnis L.
Sorry but they did not lead to the solution. I thought it would be professional to post the answer that did help. I'm more concerned with helping people that have the problem then awarding/subtracting points and not posting the solution.
RailRhoad
hi. how is this a solution to the problem? i looked at the solution.
Erx_VB.NExT.Coder
as in i didn't understand, tho im a vb dev, i can still sort of read c#
Erx_VB.NExT.Coder