Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.MVC 2.0 How display Blank textbox for Model property of Integer when integer value is zero

I have the following code:

<div class="editor-field">
<%: Html.TextBoxFor(model => model.MyId) %>
<%: Html.ValidationMessageFor(model => model.MyId) %>
<
/div>

The 'MyId' property of the model is of type integer.

When the form is in 'Create' mode, MyId value is 0. How can I, prevent 0 displaying and rather render the textbox with an empty string / blank / no value?

I have tried various forms of String.Format without success.

like image 789
Grant Sutcliffe Avatar asked Sep 07 '10 21:09

Grant Sutcliffe


1 Answers

You could use a nullable integer:

public int? MyId { get; set; }
like image 159
Darin Dimitrov Avatar answered Oct 15 '22 12:10

Darin Dimitrov