简体   繁体   中英

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?

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.

Change your model so it has nullable properties:

class YourModel {
    [Required]
    public int? Integer { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM