ASP.Net MVC 2 partialview that reads part of URL
i am creating a partialview with a controller action like:
public ActionResult GetPostsByUser(string userName) {
where userName is part of the URL:
www.example.com/User/toddM
toddM being the userName
First off.. am i going about this the right way?? if i make it a querystring ?userName=toddM it works.. but i need it to read from 开发者_如何学编程the URL. Again, this is a partialview . thanks!
Your Url sample is not "well formed" as it miss one of the controller/action.
In fact, as per the default route created by the MVC project template you should have
"{controller}/{action}/{id}", // URL with parameters
An URL like www.example.com/Post/User/toddM
would perfectly fits within the default route and so I think will work without any problem.
This one would be your action in an hypothetical PostController
public ActionResult User( string id )
{
//id will contain toddM
}
精彩评论