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?

有帮助吗?

解决方案

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 {})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top