mercredi 29 juin 2016

Some troubles w/ jQuery dialog closing

Have some partial view with own button, which is returned to the jq dialog. After clicking the button on the partial view, i need that jq dialog get closed. The following script does close the dialog, but it doesnt send data on the server. So it closes the form before sending it. Can you help please?

Script:

 <script>
        $(".close1").on("click", function (e) {
            e.preventDefault();
            $(this).closest(".dialog").dialog("close");
        });
    </script>

Partial View:

@model ManualSite.Models.Student
<div id="myform">
   @using (Ajax.BeginForm("Create", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "results"}))
   {
        @Html.HiddenFor(model => model.Id)
        @Html.LabelFor(model => model.Name)
        <br />
        @Html.TextBoxFor(model => model.Name)
        <br /><br />
        @Html.LabelFor(model => model.Surname)
        <br />
        @Html.TextBoxFor(model => model.Surname)
        <br /><br />
        @Html.LabelFor(model => model.Gpa)
        <br />
        @Html.TextBoxFor(model => model.Gpa)
        <br /><br />

    <input type="submit" name="createSubmit" value="Create" class="close1"/>
   }


</div>

jQuey Dialog:

$(document).ready(function () {
$.ajaxSetup({ cache: false });
$(".viewDialog").on("click", function (e) {
    e.preventDefault();
    $("<div></div>")
        .addClass("dialog")
        .appendTo("body")
        .dialog({
            title: $(this).attr("data-dialog-title"),
            close: function () { $(this).remove() },
            modal: true,
        })
        .load(this.href);

});

});

Aucun commentaire:

Enregistrer un commentaire