MVC:开盘后在SimpleModal AJAX弹出客户方验证停止工作和关闭一次弹出、客户、工作、MVC

2023-09-10 14:45:37 作者:出奇的可爱

我有一个simplemodal弹出窗口视图。你点击一个超链接,它会弹出窗口,如果你尝试不填写任何信息,它会显示旁边的文本框相应的验证错误信息提交popup'd形式。如果关闭模式弹出,然后再次单击超链接,它似乎没有做客户端验证,当你点击提交。它只是让它提交,然后它会赶上它在服务器端检查。为什么会打开一个模式弹出,然后关闭它,然后重新打开第二次补充验证停止工作?我使用的是demo'd在 SimpleModal演示基本OSX模式。任何建议,将不胜AP preciated。我在工地附近的检查,但如果有人有previous职位,可能是将AP preciated太大的帮助。

下面是我的局部视图文件:

 <%@控制语言=C#继承=System.Web.Mvc.ViewUserControl< NSS.Models.Company>中%>
<脚本的src =/脚本/ MicrosoftAjax.js类型=文/ JavaScript的>< / SCRIPT>
<脚本的src =/脚本/ MicrosoftMvcAjax.js类型=文/ JavaScript的>< / SCRIPT>
<脚本的src =/脚本/ MicrosoftMvcValidation.js类型=文/ JavaScript的>< / SCRIPT>
 

<%Html.EnableClientValidation(); %> <%使用(Html.BeginForm(创建,公司))    {%>     <%:Html.ValidationSummary(TRUE)%>

 <字段集>
    <传奇>新建企业和LT; /传说>

    < D​​IV CLASS =编辑标记>
        <%:Html.LabelFor(型号=> model.Company_Name)%>
    < / DIV>
    < D​​IV CLASS =主编场>
        <%:Html.TextBoxFor(型号=> model.Company_Name)%>
        <%:Html.ValidationMessageFor(型号=> model.Company_Name)%>
    < / DIV>

    < D​​IV CLASS =编辑标记>
        <%:Html.LabelFor(型号=> model.Company_Phone)%>
    < / DIV>
    < D​​IV CLASS =主编场>
        <%:Html.TextBoxFor(型号=> model.Company_Phone)%>
        <%:Html.ValidationMessageFor(型号=> model.Company_Phone)%>
    < / DIV>

    < D​​IV CLASS =编辑标记>
        <%:Html.LabelFor(型号=> model.Company_Fax)%>
    < / DIV>
    < D​​IV CLASS =主编场>
        <%:Html.TextBoxFor(型号=> model.Company_Fax)%>
        <%:Html.ValidationMessageFor(型号=> model.Company_Fax)%>
    < / DIV>

    < D​​IV CLASS =编辑标记>
        <%:Html.LabelFor(型号=> model.Company_Website)%>
    < / DIV>

    < D​​IV CLASS =主编场>
        <%:Html.TextBoxFor(型号=> model.Company_Website)%>
        <%:Html.ValidationMessageFor(型号=> model.Company_Website)%>
    < / DIV>

    &其中p为H.;
        <输入类型=提交值=创建/>
    &所述; / P>
< /字段集>
 
解决MVC各种版本 2015,2017,2019等 无法安装 卸载的方法

<%}%>

这部分是的.aspx该块所呈现的:

 < D​​IV ID ='集装箱'>
    < D​​IV ID ='内容'>
        < D​​IV ID ='OSX模态'>
            <输入类型=按钮NAME =OSX价值='示范'级='OSX演示/>
        < / DIV>

        <! - 模态内容 - >
        < D​​IV ID =OSX峰内容>
            < D​​IV ID =OSX模态的标题>创建一个新的公司和LT; / DIV>
            < D​​IV CLASS =关闭>< A HREF =#级=simplemodal闭&GT,X< / A>< / DIV>
            < D​​IV ID =OSX模态数据>
                < H2>创建一个新的公司和LT; / H>
                &所述;%Html.RenderPartial(的CreateForm,新NSS.Models.Company()); %>
                < P><按钮类=simplemodal闭>关闭< /按钮> <跨度>(或preSS ESC键或单击叠加)和LT; / SPAN>< / P>
            < / DIV>
        < / DIV>
    < / DIV>
< / DIV>
 

下面是我的验证code:

 公共类Company_Validation
{
    [必需的(AllowEmptyStrings =假,的ErrorMessage =公司名称是必需的)
    [StringLength(50的ErrorMessage =企业名称不得长于50个字符)
    公共字符串COMPANY_NAME {获得;组; }
}
 

解决方案

由于SimpleModal处理模式的内容的方式,它听起来就像是失去了有效性结合。

一种选择是使用了坚持:真正的选择,但你可能想确保清除任何填充表单值

例如:

  $(元素).modal({
    坚持:真,
    的OnClose:函数(对话){
        VAR模式=这一点;
        $('输入,文本区域',dialog.data [0])VAL('')。
        modal.close();
    }
});
 

I have a view with a simplemodal popup window. You click on a hyperlink, it pops up the window, and if you try to submit the popup'd form without filling in any information it will display the appropriate validation error message next to the textbox. If you close the modal popup and click the hyperlink again, it seems to not do the client side validation when you click the submit. It just lets it be submitted, and then it'll catch it on the server side checking. Why would opening a modal popup and then closing it, and then reopening a second time make validation stop working? I'm using the basic osx modal that is demo'd at SimpleModal Demos. Any suggestions would be greatly appreciated. I've checked around the site but if someone has a previous post that could be helpful that would be appreciated too.

Here is my partial view file:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NSS.Models.Company>" %>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

<% Html.EnableClientValidation(); %> <% using (Html.BeginForm("Create", "Companies")) {%> <%: Html.ValidationSummary(true)%>

<fieldset>
    <legend>New Company</legend>

    <div class="editor-label">
        <%: Html.LabelFor(model => model.Company_Name)%>
    </div>
    <div class="editor-field">
        <%: Html.TextBoxFor(model => model.Company_Name)%>
        <%: Html.ValidationMessageFor(model => model.Company_Name)%>
    </div>

    <div class="editor-label">
        <%: Html.LabelFor(model => model.Company_Phone)%>
    </div>
    <div class="editor-field">
        <%: Html.TextBoxFor(model => model.Company_Phone)%>
        <%: Html.ValidationMessageFor(model => model.Company_Phone)%>
    </div>

    <div class="editor-label">
        <%: Html.LabelFor(model => model.Company_Fax)%>
    </div>
    <div class="editor-field">
        <%: Html.TextBoxFor(model => model.Company_Fax)%>
        <%: Html.ValidationMessageFor(model => model.Company_Fax)%>
    </div>

    <div class="editor-label">
        <%: Html.LabelFor(model => model.Company_Website)%>
    </div>

    <div class="editor-field">
        <%: Html.TextBoxFor(model => model.Company_Website)%>
        <%: Html.ValidationMessageFor(model => model.Company_Website)%>
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>

<% } %>

That partial is rendered in this block of .aspx:

<div id='container'>
    <div id='content'>
        <div id='osx-modal'>
            <input type='button' name='osx' value='Demo' class='osx demo'/>
        </div>

        <!-- modal content -->
        <div id="osx-modal-content">
            <div id="osx-modal-title">Create a new Company</div>
            <div class="close"><a href="#" class="simplemodal-close">x</a></div>
            <div id="osx-modal-data">
                <h2>Create a new Company</h2>
                <% Html.RenderPartial("CreateForm", new NSS.Models.Company()); %>
                <p><button class="simplemodal-close">Close</button> <span>(or press ESC or click the overlay)</span></p>
            </div>
        </div>
    </div>
</div>

Here is my Validation code:

public class Company_Validation
{
    [Required(AllowEmptyStrings=false, ErrorMessage = "Company Name is required")]
    [StringLength(50, ErrorMessage = "Company Name may not be longer then 50 characters")]
    public string Company_Name { get; set; }
}

解决方案

Because of the way SimpleModal handles the contents of the modal, it sounds like it is losing the validation binding.

One option would be to use the persist: true option, but you'd probably want to make sure to clear out any populated form values.

For example:

$(element).modal({
    persist: true,
    onClose: function (dialog) {
        var modal = this;
        $('input, textarea', dialog.data[0]).val('');
        modal.close();
    }
});