0
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Microinvest.net.Models.ViewModels.SupportRusViewModel>" %>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("HelpRequest", "Form", FormMethod.Post, new {id ="formTrim" }))
   { %>
    <tr>
        <td>
            <label for="suggestion_suggestionMessage">
                <%= Resources.Dict.strSuggestionDescription%></label>
        </td>
        <td>
            <%= Html.TextAreaFor(x => x.suggestion.suggestionMessage, new { @class = "technicalQuestionTextArea" })%><span
                class="required">
                <br />
                <%= Html.ValidationMessageFor(m => m.suggestion.suggestionMessage)%></span>
        </td>
    </tr>
    <tr>
        <td>
            <label for="suggestion_systemDescription">
                <%= Resources.Dict.strSuggestionSystemDescription%></label>
        </td>
        <td>
            <%= Html.TextAreaFor(x => x.suggestion.systemDescription, new { @class = "technicalQuestionTextArea" })%><span
                class="required">
                <br />
                <%= Html.ValidationMessageFor(m => m.suggestion.systemDescription)%></span>
        </td>
    </tr>
    <% } %>

我正在该视图中加载该部分视图:

<% Html.EnableClientValidation(); %>
            <% using (Html.BeginForm("HelpRequest", "Form"))
               { %>
            <%= Html.ValidationSummary(true) %>
            <center>
                <fieldset>
                    <table cellpadding="3">
                        <tr>
                            <td valign="middle" align="right">
                                <label for="names">
                                    <%= Resources.Dict.strNames%></label>:<span class="required"></span>
                            </td>
                            <td align="left" style="width: 300px;">
                                <%= Html.TextBoxFor(m => m.names)%><span class="required"><br />
                                    <%= Html.ValidationMessageFor(m => m.names)%></span>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <label for="city">
                                    <%= Resources.Dict.strOrganisation%></label>:<span class="required"></span>
                            </td>
                            <td align="left" style="width: 300px;">
                                <%= Html.TextBoxFor(m => m.city)%>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <label for="telephone">
                                    <%= Resources.Dict.phoneNumber%></label>:<span class="required"></span>
                            </td>
                            <td align="left" style="width: 300px;">
                                <%= Html.TextBoxFor(m => m.telephone)%><span class="required"><br />
                                    <%= Html.ValidationMessageFor(m => m.telephone) %></span>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <label for="email">
                                    <%= Resources.Dict.strEnterYourEmail%></label>:<span class="required"></span>
                            </td>
                            <td align="left" style="width: 300px;">
                                <%= Html.TextBoxFor(m => m.email)%><span class="required"><br />
                                    <%= Html.ValidationMessageFor(m => m.email) %></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%= Resources.Dict.strQuestionType %>:
                            </td>
                            <td>
                                <%=Html.RadioButtonFor(m => m.questionType, "techinicalQuestion", new {@checked = "checked", @class = "questionType" })%>
                                <%= Resources.Dict.strTechnicalQuestion%>
                                <%=Html.RadioButtonFor(m => m.questionType, "suggestion", new { @class = "questionType" })%>
                                <%= Resources.Dict.strSuggestion %>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div id="typeOfQuestion">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <input id="register_button" type="submit" value="<%= Resources.Dict.strSend %>" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <br />
            </center>
            <% } %>

我正在使用该 javascript 来完成这项工作:

    function pageLoad() {
        $("#typeOfQuestion").load("/Form/TechnicalQuestionPartial");
        $(".questionType").click(function () {
            var UrlPass;
            if ($(this).val() === "techinicalQuestion") {
                UrlPass = "/Form/TechnicalQuestionPartial";
                //            $('#typeOfQuestion').load("/Form/TechnicalQuestionPartial");
            } else if ($(this).val() === "suggestion") {
                UrlPass = "/Form/SuggestionPartial";
                //            $('#typeOfQuestion').load("/Form/Suggestion");
            }
            $.ajax({
                url: UrlPass,
                success: function (data) {
                    $('#typeOfQuestion').html(data);
                    $('#typeOfQuestion').html($("#formTrim").html());
                    validateAjaxForm();
                }
            });
        });


    function validateAjaxForm() {

        $('#form0').removeData('validator');
        $('#form0').removeData('unobtrusiveValidation');
        $.validator.validate('#form0');
        $('#form0').validate().form();
//        $("form").removeData("validator");
//        $("form").removeData("unobtrusiveValidation");
//        $.validator.unobtrusive.parse("form");
//         $('#form0').validate();
    }
};

form0 是呈现的非部分视图中表单的 id 问题是

$('#form0').removeData('validator');
        $('#form0').removeData('unobtrusiveValidation');
        $.validator.validate('#form0');
        $('#form0').validate().form(); 

没有打开动态输入内容的验证

4

1 回答 1

1

您可以尝试调用:

$.validator.unobtrusive.parse($("form"));

这应该有望启用对动态添加的内容的验证。

于 2012-07-06T09:24:37.480 回答