Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 Razor, don't show default value

I'm using Html.TextBoxFor(model => model.field) which works fine, however it defaults to 0 for numbers, and to N/A for strings if they are not set, how can i possible change that such it doesn't show anything if the value is not set?

like image 364
Torben Pi Jensen Avatar asked Jun 01 '11 13:06

Torben Pi Jensen


1 Answers

You have to make the values in your model nullable, like so:

public class Model
{
    public int? Field { get; set; }
}

That way an empty value will map to the null value and vice versa.

like image 87
fretje Avatar answered Sep 21 '22 00:09

fretje