Routing to the actions with same names but different parameters

后端 未结 4 1444
无人共我
无人共我 2021-01-01 11:40

I have this set of routes:

        routes.MapRoute(
            \"IssueType\",
            \"issue/{type}\",
            new { controller = \"Issue\", action         


        
4条回答
  •  鱼传尺愫
    2021-01-01 12:07

    You can do it using an ActionFilterAttribute that checks the parameters using reflection (I tried it) but it's a bad idea. Each distinct action should have its own name.

    Why not just call your two methods "Index" and "Single", say, and live with the limitation on naming?

    Unlike methods that are bound at compile time based on matching signatures, a missing route value at the end is treated like a null.

    If you want the [hack] ActionFilterAttribute that matches parameters let me know and I'll post a link to it, but like I said, it's a bad idea.

提交回复
热议问题