@Html.Label won't allow string concatination

Posted by MrGrigg on Stack Overflow See other posts from Stack Overflow or by MrGrigg
Published on 2010-12-27T21:30:44Z Indexed on 2010/12/27 21:54 UTC
Read the original article Hit count: 150

Filed under:
|

I'm building dynamic forms based on a partial view. My view inherits a model with a single property: CatalogName { get; set; }.

I have tried this:

@Html.Label(Model.CatalogName + "-ProductNumber", "Product Number")
@Html.TextBox(Model.CatalogName + "-ProductNumber")

The HTML renders like this though:

<label for>Product Number</label>
<input name="CatatalogName-ProductNumber" type="text" />

If I write my code like this:

@Html.Label("ProductNumber-" + Model.CatalogName", "Product Number")

It will render the way I expect

<label for="ProductNumber-CatalogName">Product Number</label>

Is this a bug with MVC? Are there any answers to why my concatenation won't work the way I want it in the label, but works fine with the TextBox?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-3

Related posts about Razor