c# - HTML 文本框将 int 数据字段的默认值显示为 0

标签 c# html asp.net-mvc

我有一个包含 int 数据字段的文本框。页面加载时,默认显示 0。以下是显示文本框的代码:

<%:Html.TextBoxFor(model => model.Ssn, htmlAttributes: new { @class = "txtBox txtBoxMediumSmall" })%>

其中 model.Ssn 是一个int
为什么不为空?应该怎么做才能让它变成空白?
如果需要更多信息,请告诉我。

最佳答案

你可以这样做

public class MyModel
{
   //Nullable integer
   public int? Ssn {get; set;}  //this should be null by default

   public int SSN {get; set; } //this should be 0 by default

}

关于c# - HTML 文本框将 int 数据字段的默认值显示为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12650466/

相关文章:

c# - SQL Server CLR 静态变量设置回 null

css - Mozilla 与 Chrome Div 宽度问题。计算边界还是不计算边界?

asp.net-mvc - MVC用户控件+ ViewData

asp.net-mvc - 如何避免在 MVC4 中使用 ViewBag 在 Controller 和 View 之间传递查询值

c# - 为什么我必须将我的对象放入 HttpContext 缓存中两次才能永久保留它?

c# - 使用 NAudio 修剪 mp3 文件

c# - 当我放在启动文件夹中时,EXE 的行为有所不同

c# - 正则表达式 - 只允许字符串中有单个空格

javascript - 如何使用 JavaScript 与 Web 服务器交互

html - &lt;input type ='submit'/> 和 <button type ='submit' >text</button> 的区别