我在.NET MVC 5中有一個表單,其中用戶可以編寫一個數字,默認值爲「0」,如果用戶刪除了數字例如「233」離開這個領域是空的。表單不會提交。如何將默認值設置爲空EditorFor-field在發佈表單時.NET MVC
如何提交空白字段?
public class myModel
{
public int nummer { get; set; }
public myModel(){}
public myModel(int i) {this.nummer = i;}
}
剃刀代碼:
using (Html.BeginForm("myAction", "myController", FormMethod.Post, new { @class = "form-inline" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text- danger" })
@Html.EditorFor(model => model.nummer, new { htmlAttributes = new { @class = "form-control " } })
<input type="submit" value="submit" name="btnSubmit"/>
}
我不感興趣驗證錯誤消息,但有值設置爲「0」,默認情況下。
public int? nummer {get;組; }更改爲此 –