2014-03-07 23 views
0

我有這個AjaxForm使用劍道日期選擇器和時間選擇器後,ajaxForm不會提交

@using (Ajax.BeginForm("AttendeeAvailability", "Response", new AjaxOptions { HttpMethod = "POST", OnSuccess = "done" })) 
{ 
    @Html.ValidationSummary(true) 
    @Html.AntiForgeryToken(); 
    <div class="col-md-12"> 
     <fieldset> 
      <legend>Enter your availability</legend> 
      <div class="well"> 
       <div class="col-md-12"> 
        <div class="form-group"> 
         @Html.Kendo().DatePickerFor(m=>m.AttendeeDate).Min(Model.AppointmentStartDate.Date).Max(Model.AppointmentEndDate) 
         @*<div class="input-group date" id="DateStart"> 
          @Html.TextBoxFor(m => m.AttendeeDate, new { @class = "form-control" }) 

          <span class="input-group-addon"> 
           <span class="glyphicon glyphicon-calendar"></span> 
          </span> 
         </div>*@ 
        </div> 
       </div> 

       <div class="col-md-12"> 
        <div class="form-group"> 
         <h5><b>Please select time you are available in</b></h5> 
        </div> 
       </div> 
       <div class='col-md-6'> 
        <div class="form-group"> 
         <h6>From</h6> 
         @Html.Kendo().TimePickerFor(m=>m.AttendeeStartTime) 
         @*<div class='input-group date' id='StartTime'> 
          @Html.TextBoxFor(m => m.AttendeeStartTime, new { @class = "form-control" }) 
          <span class="input-group-addon"> 
           <span class="glyphicon glyphicon-time"></span> 
          </span> 
         </div>*@ 
        </div> 
       </div> 
       <div class='col-md-6'> 
        <div class="form-group"> 
         <h6>To</h6> 
         @Html.Kendo().TimePickerFor(m => m.AttendeeEndTime) 
         @*<div class='input-group date' id='EndTime'> 
          @Html.TextBoxFor(m => m.AttendeeEndTime, new { @class = "form-control" }) 
          <span class="input-group-addon"> 
           <span class="glyphicon glyphicon-time"></span> 
          </span> 
         </div>*@ 
        </div> 
       </div> 
       <div class="form-group"> 
        <input class="btn btn-default" type="submit" value="Add" /> 
       </div> 
      </div> 
     </fieldset> 
    </div> 

} 

這裏每當我試圖提交表單單擊添加按鈕,它不提交表單。它高度重視時間賽車手。

但是,如果我評論KendoDatepicker和timepickers,並取消註釋其他datepicker和timepicker,我的表單將被提交。任何理由?

這裏是視圖模型

public class AttendeeAvailableDateTime 
{ 

    public DateTime AppointmentStartDate { get; set; } 
    public DateTime AppointmentEndDate { get; set; } 

    public DateTime AttendeeDate { get; set; } 
    public DateTime AttendeeStartTime { get; set; } 
    public DateTime AttendeeEndTime { get; set; } 
    public int TotalAttendees { get; set; }  
} 

錯誤:

我只是試圖把驗證消息,這是我在瀏覽器中得到的驗證錯誤

The field AttendeeStartTime must be a date. 

所以,我應該改變我的模型?

如果我改變

public DateTime AttendeeStartTime { get; set; } 
public DateTime AttendeeEndTime { get; set; } 

輸入字符串,然後我得到這個錯誤

Cannot implicitly convert type `string` to 'System.DateTime?' 

在這一行

@Html.Kendo().TimePickerFor(m=>m.AttendeeStartTime) 

那麼應該怎麼辦?

回答

1

剛剛意識到,爲了使用TimePickerFor從劍道,模特的領域應該是TimeSpan型的,而不是DateTimestring