Question

I have a very simple normal route and I can't seem to get it to work. I'm kind of clueless what I'm missing.

My routing is:

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

My Controller is called AccountController and it has this method:

 public virtual ApplicationUser EditUser(String userId)

I post this URL and I get a userid that is null

 /Account/EditUser/Patrick

What am I missing?

Was it helpful?

Solution

Your route has a parameter called "id", whereas your method has a parameter called "userId". These need to match.

So either create a route, like:

routes.MapRoute(
        name: "EditUser",
        url: "Account/EditUser/{userId}",
        defaults: new { controller = "Account", action = "EditUser"});

Or change your method to be:

public virtual ApplicationUser EditUser(string id);

Note that if you choose the first option, you need to put that call before the existing default one, because any URL you enter will match against the first route which matches it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top