asp.net mvc and routing -



asp.net mvc and routing -

i have next actions in controller

public actionresult index(int? pagenumber) public actionresult details(string seofriendlyname)

and want have next routes:

~/article/ -> action = index, pagenumber = 1 ~/article/page-5 -> action = index, pagenumber = 5 ~/article/page-1 -> ~/article/ ~/article/foo -> action = details, seofriendlyname = foo

i've tried define next routes, doesn't work:

routes.maproute( null, "article/page-{pagenumber}", new { controller = "mycontroller", action = "index", pagenumber = 1 }, new[] { "mynamespace" } ); routes.maproute( null, "article", new { controller = "mycontroller", action = "index", }, new[] { "mynamespace" } ); routes.maproute( null, "article/{seofriendlyname}", new { controller = "mycontroller", action = "details", }, new[] { "mynamespace" } );

any help appreciated!

your requirements self-contradictory. example, route should selected if have article seofriendlyname == "page-6" , actual pagenumber == 2?

i'd suggest alter requirements to

~/article/ -> action = index, pagenumber = 1 ~/article/page/5 -> action = index, pagenumber = 5 ~/article/page/1 -> ~/article/ ~/article/foo -> action = details, seofriendlyname = foo

and have next routes:

routes.maproute( null, "article/page/{pagenumber}", new { controller = "mycontroller", action = "index", pagenumber = 1 }, new[] { "mynamespace" } ); routes.maproute( null, "article", new { controller = "mycontroller", action = "index", }, new[] { "mynamespace" } ); routes.maproute( null, "article/{seofriendlyname}", new { controller = "mycontroller", action = "details", }, new[] { "mynamespace" } );

update

in response comments:

for specific requirement you'll need modify routes way:

routes.maproute( null, "article", new { controller = "mycontroller", action = "index", pagenumber = 1 }, new[] { "mynamespace" } ); routes.maproute( null, "article/page/{pagenumber}", new { controller = "mycontroller", action = "index", }, new[] { "mynamespace" } ); routes.maproute( null, "article/{seofriendlyname}", new { controller = "mycontroller", action = "details", }, new[] { "mynamespace" } );

asp.net-mvc-3 asp.net-mvc-routing

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -