asp.net-mvc – MVC控制器操作参数为null

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – MVC控制器操作参数为null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有控制器名称:区域和操作名称:Incharges但我希望URL是这样的(带有一些paremeter的动作名称)

www.example.com/district/incharges/aaa

www.example.com/district/incharges/bbb

www.example.com/district/incharges/ccc

但是,调试teamName时总是在action参数中返回NULL.

路由

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

            routes.MapRoute(
            "DistrictDetails","District/Incharges/{teamName}",new { controller = "District",action = "Incharges" }
            );

调节器

但是,调试teamName时总是在action参数中返回NULL.

public class DistrictController : Controller
    {     


        public ActionResult Incharges(string teamName)
        {
            InchargePresentationVM INPVM = new InchargePresentationVM();
            INPVM.InitializePath(teamName,string.Empty);
            return View("",INPVM);
        }
}

视图

@{
    ViewBag.Title = "Index";
}

<h2>Index About</h2>

解决方法

具体路线你必须申报第一个
routes.MapRoute(
            "DistrictDetails",action = "Incharges",id = UrlParameter.Optional }

routes.MapRoute(
                name: "Default",id = UrlParameter.Optional }
            ););

猜你在找的asp.Net相关文章