Reputation: 207
For this Double Type Property, Textbox displaying zero by default
public double Longitude
{
get { return _longitude; }
set { _longitude = value; }
}
//[Required(ErrorMessage = "Please enter latitude")]
public double Latitude
{
get { return _latitude; }
set { _latitude = value; }
}
Here is my .cshtml
<div class="labeldiv">
@Html.Label("Longitude", new { Class = "lblcls" })
</div>
<div class="fielddiv">
@Html.TextBoxFor(model => model.Longitude, new { Class = "txtbox"})
</div>
<div class="cleardiv"></div>
<div class="labeldiv">
@Html.Label("Latitude", new { Class = "lblcls" })
</div>
<div class="fielddiv">
@Html.TextBoxFor(model => model.Latitude, new { Class = "txtbox"})
</div>
How can i hide this zero value in textbox
Upvotes: 1
Views: 2408
Reputation: 28588
It is because default value of double is 0, so if user leave it empty it still set it to 0. You can set it to nullable if your business logic allowed and handle that situation.
Other than this, You can set default value to input but in double case it cannot be empty:
@Html.TextBoxFor(model => model.Longitude, new { @Value = "5.5" })
Upvotes: 2