I have this code in a JavaScript function:
var url = '@Url.Action(MVC.Membership.User.ActionNames.Update, MVC.Membership.User.Name)';
url += "?userName=" + userName;
ul.append("<li><a href=" + url + "\>" + userName + "</a></li>");
Membership
is an Area
. I'm using T4MVC
to refer to Controller and Action names to avoid magic strings... :)
This JavaScript
code is part of View
that resides in the Membership
Area.
UserController
is decorated this way:
[RouteArea("Membership")]
public partial class UserController : BaseController
and the Action
method is this one:
[GET("Users/Update/{userName}")]
public virtual ActionResult Update(string userName)
The route I get in the link is this:
http://localhost:8087/membership/User/Update?userName=leniel
I expected it to be:
http://localhost:8087/membership/users/update?userName=leniel
So my question is: why the link is not in lowercase since all other links in the app are being generated with lower case letters? Is this not supported or am I forgetting some config related to AttributeRouting or the Area setup?
After the feedback from AttributeRouting creator... turns out it was my bad.
Now I understand the problem...
If I do this:
var url = '@Url.Action(MVC.Membership.Permission.ActionNames.GrantRevoke, MVC.Membership.Permission.Name, new { area = "Membership", roleName= "Teste" }, null)';
The URL is generated correctly:
var url = '/membership/permissions/grantrevoke/teste';
but if I do this:
var url = '@Url.Action(MVC.Membership.Permission.ActionNames.GrantRevoke, MVC.Membership.Permission.Name, new { area = "Membership" }, null)';
I get this:
var url = '/Membership/Permission/GrantRevoke';
It's clear that I need to pass the roleName parameter.