ASP.NET MVC routing returning null
I am trying to get a URL for the following route:
RouteTable.Routes.MapRoute(
null,
"cinema",
new
{
Controller = "CinemaListings",
Action = "ShowCinemaLandingPage",
SiteArea = "CinemaTimes",
MainLandingPage = true
});
I've tried the following methods to produce the URL:
<%:Url.Action("ShowCinemaLandingPage", "CinemaTimes", new { SiteArea = "CinemaTimes", MainLandingPage = true})%>
<%:Url.RouteUrl(new { Controller = "CinemaTimes", Action = "ShowCinemaLandingPage", SiteArea = "CinemaTimes", MainLandingPage = true })%>
I've also tried with only the controller开发者_运维技巧 and action names. I get null returned - what am I missing?
Doesn't this work?
<%:Url.Action("ShowCinemaLandingPage", "CinemaListings", new { SiteArea = "CinemaTimes", MainLandingPage = true })%>
It seems from your code that you've mixed up SiteArea
with Controller
values. So instead of providing controller name in Url.Action
, you've provided SiteArea
twice (as second parameter and as additional route value).
It is hard to understand your route. First of all, you have not given it name (passing null which I have experienced before causing problem) and then there is no place holder in there.
This cannot work without giving it a controller.
<%:Url.Action("ShowCinemaLandingPage", "CinemaTimes", new { SiteArea = "CinemaTimes", MainLandingPage = true})%>
Here you are passing controller name but since there is no controller name, no path will be matched.
So I would use - at bare minimum - this:
RouteTable.Routes.MapRoute(
"GiveMeSomeNameWillYa?",
"{Controller}/{Action}",
new
{
Controller = "CinemaListings",
Action = "ShowCinemaLandingPage",
SiteArea = "CinemaTimes",
MainLandingPage = true
});
精彩评论