0

我目前正在开发一个具有三个 UserTypes 的 asp.net mvc 应用程序。1) 管理员 2) 学校 3) 家长

我想用 3 个部分来装饰 URL,

like if it is admin then ->     Admin/{Controller}/{Action}/{id}
if Shcool ->     School/{Controller}/{Action}/{id} 
if Parent - >     Parent/{Controller}/{Action}/{id}

我试图将 routeconfig.cs 修改为

 routes.MapRoute(
    name: "Default",
    url: "School/{controller}/{action}/{id}",
    defaults: new { controller = "EstablishmentLogin", action = "Login", id = UrlParameter.Optional    });

它有效,但问题是我曾经使用过 ajax 调用,我需要将 url 从 [{Controller}/{Action}/{id}] 修改为 [School/{controller}/{Action}/{id} ]。

找出所有 ajax 调用并修改 url 会很耗时。如果这个问题有任何替代方案,请建议我。

Also I want to Organize the folders Physically as

1)Admin -> Controllers 
-> View
-> models 

2)School - > Controllers
- > Views 
-> Models`enter code here

3)Parent - > Controllers
- > Views 
- > Models 
How can i acheive this ?
4

1 回答 1

0

将它们设置为区域。右键单击您的项目-> 添加-> 区域。它将创建一个与您在问题中列出的完全一样的文件夹结构。该区域还将拥有自己的RouteConfig.cs命名版本[AreaName]AreaRegistration.cs。它就像您的主项目中的一个迷你 MVC 站点。如果您需要在区域之间或主站点与您构建的区域之间创建链接,例如...Url.Action("Action", "Controller", new { area = "AreaName" });

于 2014-01-20T17:11:45.723 回答