shlasasha
shlasasha

Reputation: 167

Bug in ASP.NET MVC - Razor?

@Html.Label acts weirdly. In example below first label is ignored, second label is rendered, and third label renders only "aaaaaaaaa"

@Html.Label("1234567890 absdfghjkl .")
@Html.Label("5555555555 ffffffffffff")
@Html.Label("3333333333. aaaaaaaaaaa")

It appears anything before period is ignored. Is there any explanation for this? Thanks!

Upvotes: 0

Views: 56

Answers (2)

CodeCaster
CodeCaster

Reputation: 151588

This is not a bug, it's just not documented: you're calling Label(string expression, string labelText, object htmlAttributes) only with an expression.

Ultimately DefaultHtmlGenerator.GenerateLabel(... string expression, string labelText, ...) is called,

You only pass the expression, which is used to determine the for attribute of the rendered <label for="...">labelText</label>. This allows you to pass an expression that looks into your model in order to tie a label to a control belonging to a model property, for example:

@Html.Label("Foo.Bar", "Toggle Foo's Bar")

If you don't pass a label text, the entire expression is used as label text, unless it contains a dot: then everything after the dot.

So pass an empty expression as first argument, then the text:

@Html.Label("", "My.Cool.Label")

Upvotes: 1

GraemeC
GraemeC

Reputation: 111

It's because of the overload you're using @Html.Label(string expression), try the overload @Html.Label(string expression, string labelText) @Html.Label("", "3333333333. aaaaaaaaaaa")

Upvotes: 1

Related Questions