Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is @Html.Label() removing some characters

When I use the following code in my razor view it renders <label for=""> someText</label> and not <label for="">1. someText</label> but I can't figure out why 1. is removed while rendering.

@Html.Label(String.Format("{0}. someText",1))

Edit: The following code renders <label for="">1# someText</label> as expected.

@Html.Label(String.Format("{0}# someText",1))
like image 561
Yots Avatar asked Apr 19 '12 12:04

Yots


1 Answers

You are misusing the Html.Label method. It is for:

Returns an HTML label element and the property name of the property that is represented by the specified expression.

That's why it gets confused if you have a point . in the first parameter because it expects a property expression there.

However, you can use the second overload:

@Html.Label("", String.Format("{0}. someText",1))

Or just write out the HTML:

<label>@String.Format("{0}. someText", 1)</label>
like image 182
nemesv Avatar answered Nov 04 '22 01:11

nemesv