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?
Asked
Active
Viewed 497 times
1
-
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 Answers
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
-1
Actually I was eventually eluding to this solution. Thanks guys for your input!
-
-
1Sorry 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 Oct 13 '09 at 16:44
-
hi. how is this a solution to the problem? i looked at the solution. – Erx_VB.NExT.Coder Jan 16 '10 at 04:30
-
as in i didn't understand, tho im a vb dev, i can still sort of read c# – Erx_VB.NExT.Coder Jan 16 '10 at 07:19