I am doing int like this:
Hello <%= Html.LabelFor(user => user.UserName)%>
But iam getting not a value which is in Property but something strange like this:
Hello User Name,
How can do it to give some value in label out?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason for this is because
Html.LabelForwill do just that – create a label for the property. In this case, it is producing a label of ‘User Name’ since the property name is UserName.You just need to look at the model (or whatever your passing to the view) to return the property value:
Html.Encode(Model.UserName)Update (since this was nearly 3 years ago but people have recently upvoted):
You can just use
<%: Model.UserName %>to get the HTML encoded value (<%=writes it as raw and<%:writes it encoded).If you’re using a Razor view engine, then
@Model.Usernamewill write it out already encoded.