需要完成http://site.com/user/add/1/2这样的url解析

使用action的参数直接获取数据的方式

Action声明如下

 public ActionResult Add(int id, int run=0)
        {
            ViewBag.clubID = id;
            if(run == 0)
                return View();
            else
                return View(exectudeAdd(id));
        }

只需要对路由进行添加即可完成

注意观察,我们需要将参数名对应到路由中,即此处的id和run,参数如上述action参数列表

context.MapRoute(
                "student_new",
                "student/{controller}/{action}/{id}/{run}",
                new { action = "Index", id = UrlParameter.Optional, run = UrlParameter.Optional }
            );
            context.MapRoute(
                "student_default",
                "student/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );

留待后查同时方便别人

2017.12.10 1:03

 

相关文章:

  • 2021-09-16
  • 2021-09-27
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-02-02
  • 2022-02-11
  • 2021-08-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案