2014-10-16 51 views
2

我正在開發一個ASP.NET MVC 5網站。我有員工模型,它看起來是這樣的:如何讓日期選擇符不填充(值爲空)?

public class Employee 
{ 
public EmployeeID {get;set;} 
//... other properties such as FirstName, Salary which are not important right now 

public DateTime? EndingDate {get; set;} //this is important 
} 

視圖的相應部件是這樣的:

<div class="form-group"> 
      @Html.LabelFor(model => model.EndingDate, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       <input name="endingDate" type="date" class="form-control datepicker" /> 
       @Html.ValidationMessageFor(model => model.EndingDate, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

正如你可以看到ENDINGDATE是空,因爲我不必填EndingDate字段。如果我想創建一個沒有填充EndingDate的員工,我會得到一個驗證錯誤,這很有意義,因爲在datepicker上,該值恰好是以下dd.mm.yyy。這發生在Google Chrome上。在Mozilla默認情況下爲null,但其行爲類似於不像日期選擇器的文本框。我正在使用引導程序的CSS類,我沒有寫一行前端開發代碼;如果你接受這種語言。我試圖添加到DisplayFormat屬性的模型,但迄今沒有成功。

任何想法?或者這是瀏覽器的問題?

回答

0

此時一個不知道任何方法。您可以嘗試一個文本框,您將填充數據並以動態方式驗證它(偶然使用Angular)。考慮從啞電話提交數據。你輸入數字並感覺數據。

0
dateTimePicker1.CustomFormat= " "; 
+0

這是一個MVC應用程序。你的意思是把它放在剃刀上? – 2014-10-16 13:22:58

相關問題