繁体   English   中英

ASP.NET剃刀:表单未提交

[英]ASP.NET razor: Form not submitting

由于我在我的DateTime属性/输入字段中添加了DisplayFormat和datepicker,因此我的表单停止了提交。 我没有收到任何错误(在chrome F12或Visual Studio中)。

编辑:我已经将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; }
    }

我看到您已将验证摘要设置为true。 难道是非强制性的验证阻止了您的表单提交,并且由于错误未附加到特定字段而您看不到它? 也许尝试将其设置为false,然后查看是否弹出任何消息? 您是否已客户端验证的同时启用了不打扰的验证?

您是否使用chrome的网络工具检查提交后是否发送了任何http帖子? 您是否也尝试过在模型中使用“ dd / mm / yyyy”?

您没有表格。 将其包装在Html.BeginForm中:

 @{ using (Html.BeginForm()) { 




              ....




    }
 }

听起来似乎太明显了,但是由于添加了“ datepicker”后它停止工作,并且您使用的是jQuery,因此应尝试添加

$(document).ready(function() {

});

包装您的“日期选择器”代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM