asp.net-mvc


Html.ActionLink forwarding the to controllers right method but not the parameter's value


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 {})

Related Links

Button click doesn't redirect user to Login page on session timeout in Kendo UI ASP MVC
Managing Session Variable in View Page After Session Expire
stop remember me popup in chrome using java-script
Session timeout does not work ( is set in web.config )
How to use FileTable in EF Code First
MVC Umbraco site bootstrap navbar strange behavior
Correct way to offer NULL value in ASP Select control
Asp.net mvc editor file upload
Bootstrap Modal and MVC Partial View
Which is the best approach for RESTful API requests?
HttpClient GetAsync Method 403 error
PDFSharp download file thru filestream
MVC Controller not being reached in Web API Project
SVN strategy for multiple apps in one solution
Exception from MVC Controller constructor
ReportViewer for MVC missing DLL dependancy

Categories

HOME
amazon-s3
actions-on-google
magento
xaml
module
ssl-certificate
android-sqlite
bolt-cms
svg.js
mocha
android-sms
jasypt
mvvm-light
android-bluetooth
regression
struts2-jquery
prestashop-1.7
wso2-das
oracle-ucm
openmodelica
reload
rebus
libssh
html-email
rational
windows-applications
cayley
amazon-cloudfront
polynomials
cadvisor
sax
unsigned-integer
structure
akka-http
clappr
html-select
subtotal
spring-websocket
detach
gosublime
querydsl
pdfstamper
data-science
paypal-rest-sdk
ecdsa
microsoft-translator
otroslogviewer
jsonstore
psychopy
pac
hostname
free-diameter
rtems
ms-jet-ace
ganglia
dump
attributerouting
itertools
sscanf
gwt-material-design
mailcore2
measurement-protocol
turnjs
struts1
pypyodbc
isapi-rewrite
sliding
strace
java-gstreamer
relaxng
spymemcached
monkeyrunner
avalonedit
translucency
bonfire
gem5
scalariform
getuikit
json-web-token
applicationstate
sqlhelper
monk
globus-toolkit
master-theorem
mouseenter
xml.modify
dotliquid
scala-pickling
nmea
deap
programmers-notepad
progressdialog
squirrelmail
noindex
katta
boost-gil
ssao
replay
renderaction
high-traffic
run-length-encoding

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App