ASP.NET MVC - 更新多个部分/视图

ASP.NET MVC - 更新多个部分/视图

问题描述:

你们如何更新(比方说)控制器行动中的两个部分去视图?例如,您的左侧导航部分为链接,右侧为您的主要内容。你的主要内容有一个它绑定的ViewModel。你们的导航页面是否有独立的ViewModel?如果是这样,那么您是否每次创建一个更大的ViewModel,每次都有主内容视图模型和左侧导航ViewModel?ASP.NET MVC - 更新多个部分/视图

+0

[如何在ASP.NET MVC中使用基本控制器创建强类型主页面](http://*.com/questions/768236/how-to-create-a-strongly-typed- master-page-using-a-base-controller-in-asp-net-mvc) – 2011-09-27 04:19:43

其实我最终回避到this solution。感谢你们的输入!

+0

请勿发表评论作为答复。并接受帮助的人。 – 2009-10-13 09:25:03

+1

对不起,但他们没有导致解决方案。我认为发布确实有帮助的答案是很专业的。我更关心帮助有问题的人,然后奖励/减去积分,而不是发布解决方案。 – RailRhoad 2009-10-13 16:44:40

+0

嗨。这是如何解决这个问题的?我看着解决方案。 – 2010-01-16 04:30:12

我会为导航页面设置一个ViewModel(例如CategoryListViewModel),另一个设置为内容页面(例如ProductListViewModel)。然后在碱控制器加载CategoryListViewModel


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()); 
    } 
} 

然后在MasterPageViewData读取的类别,并且在内容页面上的ViewPage读取的产品从Model

你可以将页面分成不同的独立部分,看看这个 页面here。在这里,您必须使用Html.RenderAction(),您必须从 下载codeplex的ASP.NET MVC Futures程序集。