Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Html.Label() not work with periods?

I'm outputting a fews strings using Html.Label(strings).

When I pass it a value with a period in it, it outputs nothing but spaces

Html.Label(company)

e.g <%: Html.Label("Bill Co.")%>

Company is a dynamic value, it will work if the value is "Bill Co" but not if it is "Bill Co.", the only difference is that period.

I should be able to pass any string to it as per HhtmlHelper.Label via msdn

  public IHtmlString Label(
        string labelText
    )

Any ideas?

like image 832
Fabii Avatar asked Feb 08 '13 19:02

Fabii


3 Answers

You can also use

<%= Html.Label("","Bill Co.")%> 

When using Html.label(), the parameter needs to be an expression that identifies the property to display and the for attribute.

like image 171
dalvir Avatar answered Sep 17 '22 14:09

dalvir


When using Html.label(), the parameter needs to be an expression that identifies the property to display. I don't think there is a property in your model named Bill Co..

You need to specify it like this:

<%: Html.Label("Name")%>  

or this:

<%: Html.Label(model => model.Name)%> 

If you just need to output a constant value as a label use the <label> tag:

<label>Bill Co.</label> 
like image 42
Nope Avatar answered Sep 18 '22 14:09

Nope


I used ToHtmlString() and that solved the issue.

Thanks

like image 24
Fabii Avatar answered Sep 18 '22 14:09

Fabii