【发布时间】:2011-04-08 04:33:15
【问题描述】:
我曾经在没有值的时候收到空字符串:
[HttpPost]
public ActionResult Add(string text)
{
// text is "" when there's no value provided by user
}
但现在我正在传递一个模型
[HttpPost]
public ActionResult Add(SomeModel Model)
{
// model.Text is null when there's no value provided by user
}
所以我必须使用?? "" 运算符。
为什么会这样?
【问题讨论】:
-
在每个模型属性上使用属性的替代解决方案(如下所述)是使用自定义模型绑定器,请参阅stackoverflow.com/questions/12734083/…
标签: asp.net-mvc string razor null viewmodel