Html.LabelFor

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Why does this return "Success" and not the bool that it represents:

This Returned <%= Html.LabelFor(m=>m.Success)%>

My Property:
private bool success = false;
public bool Success
{
get { return success; }
set { success = value; }
}

I dont even get a casting error

Thanks
 
Hi,

LabelFor is to define the label for another form field. So it makes sense to
return the property name (or the DisplayName attribute if you want something
else) rather than the property value. You may want to use Html.Label instead
(not familiar with MVC but I suppose it exists).

As a side note creating members differing only in casing is generally
considered as a bad practice (error prone and if a library can impair its
usage from non case sensitive languages)...
 
Back
Top