我有一个文本框,在初始页面加载时(并假设一个空模型)html TextBoxFor帮助器用0填充一个文本框。由于0是一个值,我想将此行为更改为“”(null什么都没有,等等。鉴于有关这方面的文献数量,我认为这应该是直截了当的;但是,我无法让它发挥作用。这就是我所拥有的(我已经解析了它以保持简单,原谅任何错误)
型号:
public class Something_ViewModel
{ [DisplayName("Feet:")]
public int Feet{ get; set; }
}
控制器:
public IActionResult RetainedOwnership()
{
Models.Analytics.Something_ViewModel RO_VM = new Models.Analytics.Something_ViewModel();
Return View(RO_VM);
}
标签助手我试过了:
@Html.TextBoxFor(Model => Model.Feet, new { id = "txtFeet", @Value = Model.Feet.ToString() ?? "" })
@Html.TextBoxFor(Model => Model.Feet, new { id = "txtFeet", Value = Model.Feet.ToString() ?? "" })
@Html.TextBoxFor(Model => Model.Feet, new { id = "txtFeet", Value = "" })
@Html.TextBoxFor(Model => Model.Feet, new {Value = "" })
@Html.TextBoxFor(Model => Model.Feet, new {@Value = "" })
@Html.TextBoxFor(Model => Model.Feet, new {id = "txtFeet"})
答案 0 :(得分:1)
您可能希望将Feet
数据类型更改为int?
。该值的默认值为null。