Search code examples
.netmodel-view-controllerlabeldefault

Add default value to label MVC .NET


I need to add the default value 0 in case the user doesn't do it.

I have this code right now, how can I change it ?

<div class="control-group">
    @Html.LabelFor(m => m.prop.PropertyId, new { @class = "control-label" })
    <div class="controls">
        @Html.TextBoxPlaceHolderFor(m => m.prop.PropertyId, new { @class = "span input-xlarge" })                
        @Html.ValidationMessageFor(m => m.prop.PropertyId)
    </div>
</div>

Thanks!


Solution

  • Are you sure you want to set a value for the label?

    Maybe you want to set it to your textbox? There is no standard TextBoxPlaceHolderFor helper but you can use regular TextBoxFor:

    @Html.TextBoxFor(m => m.prop.PropertyId, new { placeholder = "0" })
    

    Is this what you need?