views:

31

answers:

1

Hi all, 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!

+1  A: 

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 
}
Lorenzo
Works! thanks, i had the signature wrong public ActionResult User( string userName ){ and no matching route. awesome, thanks again!
toddm
You are welcome :)
Lorenzo