2009-09-30 113 views
1

你們如何更新(比方說)控制器行動中的兩個部分去視圖?例如,您的左側導航部分爲鏈接,右側爲您的主要內容。你的主要內容有一個它綁定的ViewModel。你們的導航頁面是否有獨立的ViewModel?如果是這樣,那麼您是否每次創建一個更大的ViewModel,每次都有主內容視圖模型和左側導航ViewModel?ASP.NET MVC - 更新多個部分/視圖

+0

[如何在ASP.NET MVC中使用基本控制器創建強類型主頁面](http://stackoverflow.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

回答

-1

其實我最終迴避到this solution。感謝你們的輸入!

+0

請勿發表評論作爲答覆。並接受幫助的人。 – 2009-10-13 09:25:03

+1

對不起,但他們沒有導致解決方案。我認爲發佈確實有幫助的答案是很專業的。我更關心幫助有問題的人,然後獎勵/減去積分,而不是發佈解決方案。 – RailRhoad 2009-10-13 16:44:40

+0

嗨。這是如何解決這個問題的?我看着解決方案。 – 2010-01-16 04:30:12

0

我會爲導航頁面設置一個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

0

你可以將頁面分成不同的獨立部分,看看這個 頁面here。在這裏,您必須使用Html.RenderAction(),您必須從 下載codeplex的ASP.NET MVC Futures程序集。