我的登录页面是http://localhost/account/login。用户登录后,我打算根据组对用户进行分类。
第1组将
http://localhost/group1/home/index
第2组将有
http://localhost/group2/home/index
请指出我正确的方向,是否涉及Mvc.Area?对不起MVC很新。
答案 0 :(得分:0)
试试这个
更改App_Start / RouteConfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();//You Can Add Manually
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
然后哟可以修改控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
// http://localhost:52603/group1/home/index
[Route("group1/home/index")]
public ActionResult Group1()
{
return View();
}
//http://localhost:52603/group2/home/index
[Route("group2/home/index")]
public ActionResult Group2()
{
return View();
}
}
}