0

I have popup and i get partialview from this code:

Common.Ajax({
        type: "POST",
        url: Common.QuanLyDaiLy.URL.CreateWizView,
        async: false,
        cache: false,
        dataType: "html",
        data: {
            id: agentid
        }
    }, function (data) {
        if (data != "") {
            $("#modal-edit-agent").find(".modal-title").text((agentid == undefined || agentid.length < 1) ? "Tạo mới đại lý" : "Cập nhật đại lý");
            $("#modal-edit-agent").find(".div-content").html(data);
            $("#modal-edit-agent").modal("show");
            Common.QuanLyDaiLy.RegisterEvent();
        }
        else {
            Common.ShowAlert("Thông báo", "Có lỗi xảy ra.", {
                Close: { Display: true },
            }, "close");
            return false;
        }
        Common.ShowLoading(false);

    });
  • My popup contains:

    <div class="row">
                    @using (Ajax.BeginForm("CreateWiz", "QuanLyDaiLy", null, new AjaxOptions
                    {
                        UpdateTargetId = "div-form-daily",
                        HttpMethod = "POST",
                        OnBegin = "QuanLyDaiLy.BeforeSend",
                        OnFailure = "QuanLyDaiLy.Error",
                        OnComplete = "QuanLyDaiLy.Success",
                        InsertionMode = InsertionMode.Replace
                    }, new { @class = "form-update", @role = "form", @id = "search-form" }))
                    {
                        <div class="col-xs-12 col-sm-12 col-md-12">
                            @Html.ValidationSummary(true)
                            <div id="div-form-daily">
                                @Html.Partial("_CreateOrEdit", Model)
    
                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-12 col-md-12 text-center">
                            <button class="btn bg-maroon btn-cons btn-sm" type="submit"><i class="fa fa-floppy-o fa-lg"></i>&nbsp; Lưu</button>
                            <button class="btn btn-default btn-sm" type="button" data-dismiss="modal"><i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;Quay về</button>
                        </div>
                    }
                </div>
    

but when I got it from jquery ajax it not validate from client side and AjaxOptions : OnBegin, OnFailure, OnComplete not working not fire too.

Can somebody help me?

Dan LE
  • 27
  • 1
  • 7
  • If your dynamically loading the content via ajax, then you need to reparse the validator - [Required field validations not working in JQuery Popup MVC 4](http://stackoverflow.com/questions/31768946/required-field-validations-not-working-in-jquery-popup-mvc-4/31769058#31769058) –  Sep 02 '16 at 09:26
  • thank you so much, Mr Stephen Mueke. i have done – Dan LE Sep 02 '16 at 09:37
  • It validated, but it not fire events: OnBegin, OnFailure, OnComplete . Do you know why? – Dan LE Sep 02 '16 at 09:48
  • That's a separate issue and you need to ask a new question with the relevant code (we d not even know what those are) (and they will not fire if the for is invalid) –  Sep 02 '16 at 09:50
  • Thank you, Stephen – Dan LE Sep 02 '16 at 10:21
  • Yes I know that, you always need to reference ajax unobtrusive file : **jquery.unobtrusive-ajax.min.js** – tika Apr 04 '18 at 18:34

0 Answers0