asp.net mvc5 action多個參數


需要完成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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM