创建视图模型:
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