我正在研究围绕体育赛事的应用程序。有足球比赛和网球比赛等不同类型的赛事。根据比赛的类型,我希望由另一个区域处理请求。但事件及其比赛类型可由应用程序的用户配置并存储在数据库中。基于路线参数值的asp.net mvc动态区域选择
Currrently我有概念的证明了这一点:
public class SoccerTournamentAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "SoccerTournament";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
var soccerTournaments = new string[] { "championsleague", "worldcup" };
foreach (var tournament in soccerTournaments)
{
context.MapRoute(
string.Format("SoccerTournament_default{0}", tournament),
string.Format("{0}/{{controller}}/{{action}}/{{id}}", tournament),
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Mvc3AreaTest1.Areas.SoccerTournament.Controllers" }
);
}
}
}
,我想soccerTournaments来自数据库(不是问题),它仅适用,但我也希望它的工作很快问作为一个新的事件/比赛类型记录被添加到数据库中,并且在这种情况下不起作用。
如何使区域选择动态而不是硬编码到路线中?