0
<%= Html.LabelFor(model => model.UserName) %>

public ActionResult EditUser(string UserName)
{
    //to do some thing
}

I have a 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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.