I have this line of code within my .aspx file
<label title="<%= Model.ProductName %>"></label>
why is it when I run it, the label is not showing at all.
yet if I do something like this it would work:
<%: Html.LabelFor(model => model.ProductName) %>
I would really like for the first method to work, is there a way?
thank you
bzlm
9,7476 gold badges70 silver badges92 bronze badges
1 Answer 1
It's because you need to provide contents for this label:
<label title="some title" for="ProductName">
<%: Model.ProductName %>
</label>
The way you wrote your markup the <label>
tag is empty. Also make sure you properly HTML encode the contents. Notice in my example the usage of <%:
(available only in ASP.NET 4) instead of <%=
. If you are running on previous versions you could use the the following:
<label title="some title" for="ProductName">
<%= Html.DisplayFor(x => x.ProductName) %>
</label>
answered Jul 2, 2011 at 17:21
3 Comments
Chen Lu
Thanks for your help, there is another problem, is there a way to set the width for <%: Html.TextBoxFor(model => model.Synopsis, new { @class = "wide" })%> I tried adding the class in the css file, but didn't work
Darin Dimitrov
@Chen Lu, in your separate CSS file you could try defining the
wide
rule like this: .wide { width: 200px; }
.Chen Lu
It worked out this way actually: <%: Html.TextBoxFor(model => model.Synopsis, new {style="width:300px"} )%> Thanks for your help!
label
HTML element. :)