Domanda

In my view I have

<dt>User Name</dt>
<dd>@Model.UserName</dd>

This shows proper user name, also I have an Html.ActionLink in the same view

@Html.ActionLink("Change Password", "ChangeNonAdminPassword", "Account", new { area = ""},new{userName=Model.UserName})

Though this actionlink sends me to right controller method but the userName value i'm getting is always null.

Here is the get method in controller

[HttpGet]
public ActionResult ChangeNonAdminPassword(string userName)
{
    var changePassword = new ChangePassword {UserName = userName};
    return View(changePassword);
}

The question is why is the userName always null in get method, and what should I do to send the proper value?

È stato utile?

Soluzione

You're passing userName into the HTML Attributes overload. You need to add it to the route values overload, the same as area. Use this instead:

@Html.ActionLink("Change Password", "ChangeNonAdminPassword", "Account", new { area = "", userName = Model.UserName}, new {})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top