Templates by BIGtheme NET
Anasayfa / Asp.MVC / Asp.NET MVC sumbit ajax form

Asp.NET MVC sumbit ajax form

@{
    Layout = null;
}

@model CMS.Admin.Models.PostModel
@using (Ajax.BeginForm("Ajax", "Post", new AjaxOptions
{
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    OnSuccess = "updateSuccess()",
    OnFailure = "dialogFailure()",
    OnBegin = "dialogBegin()",
    OnComplete = "dialogComplete()",
    UpdateTargetId = "dialogResult"
}))
{
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
        <h4 class="modal-title">Firma</h4>
    </div>
    <div class="modal-body">
        <div class="row">
            <div class="col-md-12">
                <div class="portlet-body form">
                    <div class="form-horizontal" role="form">
                        @Html.HiddenFor(m => m.ID)
                        <div class="form-body">
                            <div class="form-group">
                                @Html.LabelFor(m => m.SIRA, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(m => m.SIRA, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.BASLIK, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(m => m.BASLIK, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.META, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(m => m.META, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.TAG, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(m => m.TAG, new { @class = "form-control" })
                                </div>
                            </div>


                            <div class="form-group">
                                @Html.LabelFor(m => m.ACIKLAMA, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    @Html.TextAreaFor(m => m.ACIKLAMA, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group form-md-line-input">
                                @Html.LabelFor(m => m.DURUM, new { @class = "control-label col-md-3" })
                                <div class="col-md-9">
                                    <div class="md-checkbox-list">
                                        <div class="md-checkbox">
                                            @Html.CheckBoxFor(m => m.DURUM, new { @class = "md-check" })
                                            <label for="DURUM">
                                                <span></span>
                                                <span class="check"></span>
                                                <span class="box"></span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn default" data-dismiss="modal">Vazgeç</button>
        <button id="btnKaydet" type="submit" class="btn blue btn-sumbit">Kaydet</button>
    </div>
}
<script>
    $("body").on("submit", "#form0", function(e){
        e.preventDefault();
        var form = $("#form0");
        Post(form.attr("data-ajax-method"), form.attr("action"), form.serialize(), function (e) {
            if (parseInt(e) == 1) {
                ShowMessage("", "Güncellendi", "success");
                var table = $('#example').DataTable().ajax.reload();
                $('#ajax').modal("hide");
            }
            else
                ShowMessage("", "Güncelleme Yapılamadı. Hata Kodu : " + e, "error")();
        });
    });
</script>