开发者

MVC 3 Razor, don't show default value

开发者 https://www.devze.com 2023-03-09 14:46 出处:网络
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开发者_Python百科 suc

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开发者_Python百科 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; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号