創建視圖模型:
public class UserViewModel {
public myApplication.Models.User User;
public string PartialViewName;
public PartialViewModelBase Tab;
}
每個選項卡,從PartialViewModelBase衍生創建視圖模型:
public abstract class PartialViewModelBase {
}
public class Tab1PartialViewModel : PartialViewModelBase {
...
}
public class TabNPartialViewModel : PartialViewModelBase {
...
}
然後進行查看和PartialViews強類型:
查看:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<UserViewModel>" %>
PartialViews:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Tab1PartialViewModel>" %>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TabNPartialViewModel>" %>
然後在您的視圖,你可以用你的部分看法吧:
<% Html.RenderPartial(Model.PartialViewName, Model.Tab); %>
在你的控制器動作:
public ActionResult YourAction(string tab)
{
// check if tab is valid !!!
var model = new UserViewModel {
User = new myApplication.Models.User();
PartialViewName = tab;
Tab = TabRepository.GetTabByName(tab);
/*
* or
* Tabs = (new Dictionary<string, type> {
* {"Tab1", typeof(Tab1PartialViewName)},
* {"TabN", typeof(TabNPartialViewName)}
* })[tab];
*/
};
Return View(model);
}
希望這有助於。
我很驚訝,JQuery UI選項卡是全客戶端。 – erikkallen 2009-06-11 22:14:39
不,他們不是,有一個選項可以通過ajax加載它們:http://docs.jquery.com/UI/Tabs#option-ajaxOptions – 2009-06-12 01:32:56