2012-04-24 110 views
1

由於我添加了一個DisplayFormat和datepicker到我的DateTime屬性/ inputfields,我的表單停止提交。我沒有得到任何錯誤(在鉻F12或Visual Studio中)。ASP.NET剃鬚刀:表單不提交

編輯:我已將Displayformat設置爲dd/MM/yyyy並將日期選擇器設置爲「dd/mm/yyyy」。但那也沒有解決它。

@using (Html.BeginForm("CreateCampaign", "Home")) { 
    @Html.ValidationSummary(true) 
    <fieldset> 
     <legend>Campaign</legend> 
     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.CampaignName) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.CampaignName) 
      @Html.ValidationMessageFor(model => model.Campaign.CampaignName) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.WebsiteUrl) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.WebsiteUrl) 
      @Html.ValidationMessageFor(model => model.Campaign.WebsiteUrl) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.PrivacyPolicyUrl) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.PrivacyPolicyUrl) 
      @Html.ValidationMessageFor(model => model.Campaign.PrivacyPolicyUrl) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.TermsUrl) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.TermsUrl) 
      @Html.ValidationMessageFor(model => model.Campaign.TermsUrl) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.PricepageUrl) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.PricepageUrl) 
      @Html.ValidationMessageFor(model => model.Campaign.PricepageUrl) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.Startdate) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.Startdate) 
      @Html.ValidationMessageFor(model => model.Campaign.Startdate) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.Enddate) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.Enddate) 
      @Html.ValidationMessageFor(model => model.Campaign.Enddate) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.Starthour) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownListFor(model => model.Campaign.Starthour, new SelectList(Model.Hours)) 
      @Html.ValidationMessageFor(model => model.Campaign.Starthour) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.Endhour) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownListFor(model => model.Campaign.Endhour, new SelectList(Model.Hours)) 
      @Html.ValidationMessageFor(model => model.Campaign.Endhour) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.PMAM) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownListFor(model => model.Campaign.PMAM, new SelectList(Model.AMPM, "key", "value")) 
      @Html.ValidationMessageFor(model => model.Campaign.PMAM) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.Language) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownListFor(model => model.Campaign.Language, new SelectList(Model.Languages, "key", "value")) 
      @Html.ValidationMessageFor(model => model.Campaign.Language) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.FK_ID_MerchantApp) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Campaign.FK_ID_MerchantApp) 
      @Html.ValidationMessageFor(model => model.Campaign.FK_ID_MerchantApp) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Campaign.CampaignType) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownListFor(model => model.Campaign.CampaignType, new SelectList(Model.Types, "key", "value")) 
      @Html.ValidationMessageFor(model => model.Campaign.CampaignType) 
     </div> 
     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
} 
<script type="text/javascript"> 
    $('#Campaign_Startdate').datepicker({ 
     dateFormat: "DD, d MM, yy", 
     minDate: new Date() 
    }); 
    $('#Campaign_Enddate').datepicker({ 
     dateFormat: "DD, d MM, yy", 
     minDate: new Date() 
    }); 

</script> 
<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 




     public class Campaign 
     { 
      #region CTor 
      public Campaign() 
      { 
      } 
      #endregion 

      #region Properties 

      [XmlElement(ElementName = "Id_campaign")] 
      public string ID_Campaign { get; set; } 
      [XmlElement(ElementName = "Campaignname")] 
      public string CampaignName { get; set; } 
      [XmlElement(ElementName = "Websiteurl")] 
      public string WebsiteUrl { get; set; } 
      [XmlElement(ElementName = "Privacypolicyurl")] 
      public string PrivacyPolicyUrl { get; set; } 
      [XmlElement(ElementName = "Termsurl")] 
      public string TermsUrl { get; set; } 
      [XmlElement(ElementName = "Pricepageurl")] 
      public string PricepageUrl { get; set; } 
      [XmlElement(ElementName = "Maxcredit")] 
      public Int32 MaxCredit { get; set; } 
      [XmlElement(ElementName = "Fk_id_currency")] 
      public string FK_ID_Currency { get; set; } 
      [XmlElement(ElementName = "Maxscans")] 
      public short MaxScans { get; set; } 
      [XmlElement(ElementName = "Startdate")] 
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:ddd, MMM d, yyyy}")] 
      public DateTime Startdate { get; set; } 
      [XmlElement(ElementName = "Enddate")] 
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:ddd, MMM d, yyyy}")] 
      public DateTime Enddate { get; set; } 
      [XmlElement(ElementName = "Starthour")] 
      public short Starthour { get; set; } 
      [XmlElement(ElementName = "Endhour")] 
      public short Endhour { get; set; } 
      [XmlElement(ElementName = "Pmam")] 
      public string PMAM { get; set; } 
      [XmlElement(ElementName = "Language")] 
      public string Language { get; set; } 
      [XmlElement(ElementName = "Fk_id_merchantapp")] 
      public string FK_ID_MerchantApp { get; set; } 
      [XmlElement(ElementName = "Campaigntype")] 
      public string CampaignType { get; set; } 
      [XmlElement(ElementName = "Createtimestamp")] 
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:ddd, MMM d, yyyy}")] 
      public DateTime CreateTimestamp { get; set; } 
      [XmlElement(ElementName = "Lastupdate")] 
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:ddd, MMM d, yyyy}")] 
      public DateTime LastUpdate { get; set; } 
      [XmlElement(ElementName = "Lastupdateby")] 
      public string LastUpdateBy { get; set; } 
      [XmlElement(ElementName = "Status")] 
      public short Status { get; set; } 
    } 
+0

當你說它'沒有提交' - 你的意思是瀏覽器沒有發送它(在這種情況下,這是一個標記問題)?或者數據在服務器上沒有被正確讀取? – 2012-04-24 09:19:28

+0

當我點擊「提交」按鈕時,沒有任何反應。不要認爲這是一個標記問題,否則鉻F12會投訴它。 – Reinard 2012-04-24 09:20:13

+0

而我沒有這個問題,直到我加入DateFormat – Reinard 2012-04-24 09:20:52

回答

3

我看到您的驗證摘要設置爲true。難道說不顯眼的驗證會阻止你的表單被提交,並且你不能看到它,因爲錯誤沒有附加到特定的字段?也許,嘗試將其設置爲false,並查看是否有任何東西彈出?你有unobtrusive validation turned on以及客戶端驗證?

您是否使用chrome的網絡工具檢查提交時是否發送了任何http post?你有沒有嘗試過在模型中使用「dd/mm/yyyy」?

+0

請拍攝我。感謝您的修復。 datepicker不工作atm,但我會找出它有什麼問題。 – Reinard 2012-04-24 10:19:50

1

您沒有表格。敷在Html.BeginForm:

@{ using (Html.BeginForm()) { 




       .... 




    } 
} 
+0

有,只是沒有複製到我的問題,對不起。 – Reinard 2012-04-24 09:37:54

1

這聽起來太明顯了,但因爲它阻止你添加的「日期選擇器」後工作,而你使用jQuery,你應該嘗試添加

$(document).ready(function() { 

}); 

包裹你的'datepicker'代碼。

+0

我剛剛刪除了與datepicker和DisplayFormat有關的所有內容,並且我的表單仍未提交。 感謝您的提示。 – Reinard 2012-04-24 09:51:32