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
2009-09-30 18:04:37
A:
Actually I was eventually eluding to this solution. Thanks guys for your input!
RailRhoad
2009-10-01 13:45:47
Do not post comments as answer. And accept the one that helped.
Arnis L.
2009-10-13 09:25:03
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
2009-10-13 16:44:40
hi. how is this a solution to the problem? i looked at the solution.
Erx_VB.NExT.Coder
2010-01-16 04:30:12
as in i didn't understand, tho im a vb dev, i can still sort of read c#
Erx_VB.NExT.Coder
2010-01-16 07:19:32