Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using ASP.NET MVC 2 and I'm struggling to understand how can I use the Html.LabelFor helpet method.


Assuming I have a model:

public class Person
{
public string lbmodelno { get; set; }}
}

XML
In my view, if I write:

      <%: Html.LabelFor(model => model.lbmodelno ) %>



in page loads in view source iam getting

XML
<div class="leftcontent">
                         <label for="lbmodelno">lbmodelno</label>
                    </div>


but i need

<label for="lbmodelno"></label>

so label should be empty when page load. it also override value iam getting from database.


Thanks for help.
Posted
Comments
Jameel VM 22-Jul-13 8:54am    
where is your actionresult.Please post that also.

1 solution

Add an attribute DisplayName() which is in the namespace using System.ComponentModel; like below
C#
public class Person
{
[DisplayName("")]
public string lbmodelno { get; set; }}
}


Hope this helps
 
Share this answer
 
v2
Comments
Ryder24 22-Jul-13 9:03am    
thanks i will try.. 1 more doubt..

i have nearly 5 variables like

public class Person
{
public string lbmodelno { get; set; }}
public string A{ get; set; }}
public string B { get; set; }}
public string C { get; set; }}
public string D { get; set; }}
public string F { get; set; }}
public string G { get; set; }}
}

should i include [DisplayName("")] for all ??
Ryder24 22-Jul-13 9:11am    
in page load it work fine but i kept one button when button is clicked it getting value from database and assign value to label in that time to it showing blank. how to avoid this??? i want value to shown in label when button is clicked.
Jameel VM 22-Jul-13 11:08am    
why you are posting label value?
Jameel VM 22-Jul-13 11:11am    
Please use the appropriate control for your requirement. Label is for providing a label for particular control. for displaying a text from the db use Html.DisplayFor()
Ryder24 22-Jul-13 14:24pm    
@Jameel M. ya u ryt.. i used Html.DisplayFor() problem solved. thanks lot dude

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900