0

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; }}
}

In my view, if I write:

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

in page loads im getting im getting

enter image description here

and in view source

enter image description here

but i dont need the default text "lbmodelno". in page load i need empty label. and it also overide value im getting from database. how to avoid this ?? im using mvc 2.0 i tried almost all ways but nothing help me.

How do I achieve that?

Thanks.

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
Ryder
  • 514
  • 1
  • 7
  • 27

1 Answers1

0

Add a DisplayName attribute to your lbmodelno field, like this:

using System.ComponentModel;
public class Person
{
    [DisplayName("")]
    public string lbmodelno { get; set; }
}
dlebech
  • 1,817
  • 14
  • 27
  • sorry. still im getting same problem. – Ryder Jul 22 '13 at 12:06
  • Ah, it might be because you are using MVC 2 which did not have a `Display` attribute but it has a `DisplayName` attribute. Try that instead. I have updated the answer and I found the hint [here](http://stackoverflow.com/a/2518386/2021517). – dlebech Jul 22 '13 at 12:29
  • 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 too it showing blank. how to avoid this??? i want value to shown in label when button is clicked. – Ryder Jul 22 '13 at 13:43
  • 1
    You want the label to update when a button is pressed? A label is not so good for that. The label describes a field so in most cases it should not be dynamic. If you are trying to display the _value_ of `lbmodelno` then you can use `DisplayFor` instead of `LabelFor`. – dlebech Jul 22 '13 at 13:54
  • awesome. thanks lot i nearly spend 5 hours to find this.. Its my 1st mvc project. thanqs lot – Ryder Jul 22 '13 at 14:05