Html.TextboxFor default value for Integer/Decimal to be Empty instead of 0

In your model add DisplayFormat attribute

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#.#}")]  
decimal  InterestRate { get; set; }

View

@Html.TextBoxFor(model => model.InterestRate)

This outputs empty instead of 0.
More format examples here

Update

TextBoxFor does`s not works with format, but EditorFor does:

@Html.EditorFor(model => model.InterestRate)

Update 2

It does work for TextBoxFor this way:

@Html.TextBoxFor(model => model.InterestRate, "{0:#.#}")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)