asp.net mvc html.labelfor
<%= Html.LabelFor(model => model.UserName) %>
public ActionResult EditUser(string UserName)
{
//to do some thing
}
I have a 开发者_JAVA百科label on my .aspx page and i have a button which calls edit user button in controller. The value of username is not being passed. I am getting a null. How can I get the value?
The LabelFor helper simply generates a <label>
tag whose value is never sent to the server when you submit the form. You could use a hidden field in order to include the value when the form is submitted:
<%= Html.HiddenFor(x => x.UserName) %>
Also sending the username in a GET/POST request seems like a security risk. If your site is using authentication I would recommend you fetching the username of the authenticated user from the authentication cookie.
精彩评论