I have controller BlogController with a couple of actions:
1)Index(string id) - show all posts/show single post if parameter id specified
2)New() - add new post
3)Delete() - delete post
4)And some more another actions
So if i type in browser mysite/blog
i could see all posts if i type mysite/blog/postnameid
i want to see single post.
the problem is when i type mysite/blog/postnameid
it is not working (The resource cannot be found.
), but if i type mysite/blog/index/postnameid
this way it is working. How could i make mysite/blog/postnameid
to work as well.
Here is my blog route in global.ascx
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRouteLowercase(
"Blog", // Route name
"Blog/{action}/{id}", // URL with parameters
new { controller = "Blog", action = "Index" } // Parameter defaults
);
routes.MapRouteLowercase(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Than if i change it like that
routes.MapRouteLowercase(
"Blog", // Route name
"Blog/{id}", // URL with parameters
new { controller = "Blog", action = "Index" } // Parameter defaults
);
the mysite/blog/postnameid
working but all another actions like New(), Delete() stop working after that (The resource cannot be found.
)
UPDATE:
I forgot to mention that id is sting, not int. so from @Darin answer i changed new { id = @"w+" }
to new { id = @"d+" }
and all seams to be working but now when i typed blog/new
for example, it is routing to show/new
insteard blog/new
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…