Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Asp.NETMVC引导程序4表单验证不';不停止事件(不起作用)?_Javascript_Asp.net Mvc_Validation_Asp.net Mvc 4_Bootstrap 4 - Fatal编程技术网

Javascript Asp.NETMVC引导程序4表单验证不';不停止事件(不起作用)?

Javascript Asp.NETMVC引导程序4表单验证不';不停止事件(不起作用)?,javascript,asp.net-mvc,validation,asp.net-mvc-4,bootstrap-4,Javascript,Asp.net Mvc,Validation,Asp.net Mvc 4,Bootstrap 4,我正在使用Asp.NETMVC开发一个调查应用程序 我有一个名为Index.cshtml的页面,该页面有一个问题表和一个“添加新”按钮。单击按钮后,将使用jQuery打开一个弹出窗口。我正在从控制器调用一个视图来填充名为AddOrEdit.cshtml(子页面)的jQuery对话框。我正在添加新的问题和选项。问题是一个文本字段,其选项添加到可编辑表中。单击提交按钮后,将触发提交表单事件(保存或更新)。Bootstrap 4验证不会停止事件,ajax调用正在工作,并向控制器发送请求。如何从输入字段

我正在使用Asp.NETMVC开发一个调查应用程序

我有一个名为Index.cshtml的页面,该页面有一个问题表和一个“添加新”按钮。单击按钮后,将使用jQuery打开一个弹出窗口。我正在从控制器调用一个视图来填充名为AddOrEdit.cshtml(子页面)的jQuery对话框。我正在添加新的问题和选项。问题是一个文本字段,其选项添加到可编辑表中。单击提交按钮后,将触发提交表单事件(保存或更新)。Bootstrap 4验证不会停止事件,ajax调用正在工作,并向控制器发送请求。如何从输入字段配置Bootstrap 4验证表单?这就是我所指的来源

Index.cshtml

@{
ViewBag.Title = "Soru Listesi";
}

<h2>Soru Oluşturma</h2>
<a class="btn btn-success" style="margin-bottom: 10px" 
onclick="PopupForm('@Url.Action("AddOrEdit","Question")')"><i class="fa fa-plus"></i> Yeni Soru 
Oluştur</a>
<table id="questionTable" class="table table-striped table-bordered accent-blue" style="width: 100%">
<thead>
    <tr>
        <th>Soru No</th>
        <th>Soru Adı</th>
        <th>Oluşturma Tarihi</th>
        <th>Güncelleme Tarihi</th>
        <th>Güncelle/Sil</th>
    </tr>
</thead>
</table>
<link href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />



@section Scripts{
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap4.min.js"></script>

<script>


    var Popup, dataTable;
    $(document).ready(function () {

        dataTable = $("#questionTable").DataTable({
            "ajax": {
                "url": "/Question/GetData",
                "type": "GET",
                "datatype": "json"
            },
            "columnDefs": [
                { targets: 2 }
            ],
            "scrollX": true,
            "scrollY": "auto",
            "columns": [
                { "data": "QuestionId" },
                { "data": "QuestionName" },
                {
                    "data": "CreatedDate",
                    "render": function (data) { return getDateString(data); }
                },
                {
                    "data": "UpdatedDate",
                    "render": function (data) { return getDateString(data); }
                },
                {
                    "data": "QuestionId",
                    "render": function (data) {
                        return "<a class='btn btn-primary btn-sm' onclick=PopupForm('@Url.Action("AddOrEdit", "Question")/" +
                            data +
                            "')><i class='fa fa-pencil'></i> Güncelle</a><a class='btn btn-danger btn-sm' style='margin-left:5px' onclick=Delete(" +
                            data +
                            ")><i class='fa fa-trash'></i> Sil</a>";
                    },
                    "orderable": false,
                    "searchable": false,
                    "width": "150px"
                }
            ],
            "language": {
                "emptyTable":
                    "Soru bulunamadı, lütfen <b>Yeni Soru Oluştur</b> butonuna tıklayarak yeni soru oluşturunuz. "
            }
        });
    });


    function getDateString(date) {
        var dateObj = new Date(parseInt(date.substr(6)));
        let year = dateObj.getFullYear();
        let month = (1 + dateObj.getMonth()).toString().padStart(2, '0');
        let day = dateObj.getDate().toString().padStart(2, '0');
        return day + '/' + month + '/' + year;
    };


    function PopupForm(url) {
        var formDiv = $('<div/>');
        $.get(url)
            .done(function (response) {
                formDiv.html(response);
                Popup = formDiv.dialog({
                    autoOpen: true,
                    resizable: true,
                    title: 'Soru Detay',
                    modal: true,
                    height: 'auto',
                    width: '700',
                    close: function () {
                        Popup.dialog('destroy').remove();
                    }

                });
            });
    }

    function SubmitForm(form) {
        event.preventDefault();
        if (form.checkValidity() === false) {
            event.preventDefault();
            event.stopPropagation();
        }
        form.classList.add('was-validated');

        var question = {};
        question.questionId = $('#QuestionId').val();
        question.questionName = $('#QuestionName').val();
        var options = new Array();
        $("#questionForm TBODY TR").each(function () {
            var row = $(this);
            var option = {};
            option.optionId = row.find("TD").eq(0).html();
            option.optionName = row.find("TD").eq(1).html();
            option.questionId = 0;
            option.isActive = true;
            option.status = true;
            options.push(option);
        });

        question.options = options;
        question.responses = new Array();
        $.ajax({
            type: "POST",
            url: form.action,
            data: JSON.stringify(question),
            contentType: "application/json",
            success: function (data) {
                if (data.success) {
                    Popup.dialog('close');
                    dataTable.ajax.reload();
                    $.notify(data.message,
                        {
                            globalPosition: "top center",
                            className: "success",
                            showAnimation: "slideDown",
                            gap: 1000
                        });
                }
            },
            error: function (req, err) {
            },
            complete: function (data) {
            }
        });
    }



    function ResetForm(form) {
        Popup.dialog('close');
        return false;
    }

    function Delete(id) {
        if (confirm('Bu soruyu silmek istediğinizden emin misiniz?')) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("Delete", "Question")/' + id,
                success: function (data) {
                    if (data.success) {
                        dataTable.ajax.reload();
                        $.notify(data.message,
                            {
                                className: "success",
                                globalPosition: "top center",
                                title: "BAŞARILI"
                            });
                    }
                }

            });
        }
    }

</script>
}
@using MerinosSurvey.Models
@model Questions
@{
 Layout = null;
}

@using (Html.BeginForm("AddOrEdit", "Question", FormMethod.Post, new { @class = "needs-validation", 
novalidate = "true", onsubmit = "return SubmitForm(this)", onreset = "return ResetForm(this)", id = 
"questionForm" }))
{
<div class="form-group row">
    @Html.Label("QuestionId", "Soru No", new { @class = "col-form-label col-md-3" })
    <div class="col-md-9">
        @Html.TextBoxFor(model => model.QuestionId, new { @readonly = "readonly", @class = "form-control" })

    </div>
</div>
<div class="form-group row">
    @Html.Label("QuestionName", "Soru Adı", new { @class = "col-form-label col-md-3" })
    <div class="col-md-9">
        @Html.EditorFor(model => model.QuestionName, new { htmlAttributes = new { @class = "form-control", required = "true" } })
        <div class="valid-feedback"><i class="fa fa-check">Süpersin</i></div>
        <div class="invalid-feedback "><i class="fa fa-times">Soru adı zorunludur.</i></div>
    </div>
</div>


@*<div class="form-group row">
        @Html.LabelFor(model => model.CreatedDate, new { @class = "form-control-label col-md-3"})
        <div class="col-md-9">
            @Html.EditorFor(model => model.CreatedDate, "{0:yyyy-MM-dd}", new { htmlAttributes = new { @class = "form-control", type = "date", @readonly = "readonly",required="false" } })

        </div>
    </div>*@


<div class="table-wrapper form-group table-responsive-md">
    <div class="table-title">
        <div class="form-group row">
            <div class="col-md-9">Seçenekler</div>
            <div class="col-md-3">
                <button type="button" class="btn btn-success add-new" style="margin-bottom: 10px"><i class="fa fa-plus"></i>Seçenek Ekle</button>
            </div>
        </div>
    </div>
    <table class="table optionTable">
        <thead>
            <tr>
                <th scope="col">Seçenek Id</th>
                <th scope="col">Seçenek Adı</th>
                <th scope="col">Güncelle/Sil</th>
            </tr>

        </thead>
        <tbody>
            @foreach (Options options in Model.Options)
                {
                    <tr>
                        <td>@options.OptionId</td>
                        <td>@options.OptionName</td>
                        <td>
                            <a class="add btn btn-primary btn-sm" title="Add" data-toggle="tooltip"><i class="fa fa-check">Onayla</i></a>
                            <a class="edit btn btn-secondary btn-sm" title="Edit" data-toggle="tooltip"><i class="fa fa-pencil">Güncelle</i></a>
                            <a class="delete btn-danger btn-sm" title="Delete" data-toggle="tooltip"><i class="fa fa-trash">Sil</i></a>
                        </td>
                    </tr>
                }
        </tbody>
    </table>
</div>


<div class="form-group row">

    <button type="submit" class="btn btn-primary btnSubmit" style="margin-bottom: 10px"><i class="fa fa-save"></i>Kaydet</button>
    <button type="reset" class="btn btn-secondary" style="margin-bottom: 10px" ><i class="fa fa-trash"></i>İptal</button>

</div>
}
<script>
$(document).ready(function () {
    $('[data-toggle="tooltip"]').tooltip();
    //var actions = $("table.optionTable td:last-child").html();

    var actions =
        ' <a class="add btn btn-primary btn-sm" title="Add" data-toggle="tooltip"><i class="fa fa-check">Onayla</i></a>' +
        '<a class="edit btn btn-secondary btn-sm" title="Edit" data-toggle="tooltip"><i class="fa fa-pencil">Güncelle</i></a>' +
        '<a class="delete btn-danger btn-sm" title="Delete" data-toggle="tooltip"><i class="fa fa-trash">Sil</i></a>';

    // Append table with add row form on add new button click
    $(".add-new").click(function () {
        debugger;
        $(this).attr("disabled", "disabled");
        $(".btnSubmit").attr("disabled", "disabled");
        var index = $("table.optionTable tbody tr:last-child").index();
        var row = '<tr>' +
            '<td>0</td>' +
            '<td><input type="text" class="form-control" name="optionName" id="optionName"></td>' +
            '<td>' + actions + '</td>' +
        '</tr>';
        $("table.optionTable").append(row);
        $("table.optionTable tbody tr").eq(index + 1).find(".add, .edit").toggle();
        $('[data-toggle="tooltip"]').tooltip();
    });



    // Add row on add button click
    $(document).on("click", ".add", function () {
        var empty = false;
        var input = $(this).parents("tr").find('input[type="text"]');
        input.each(function () {
            if (!$(this).val().trim()) {
                $(this).addClass("error");
                empty = true;
            } else {
                $(this).removeClass("error");
            }
        });
        $(this).parents("tr").find(".error").first().focus();
        if (!empty) {
            input.each(function () {
                $(this).parent("td").html($(this).val().trim());
            });
            $(this).parents("tr").find(".add, .edit").toggle();
            $(".add-new").removeAttr("disabled");
            $(".btnSubmit").removeAttr("disabled");

        }
    });

    // Edit row on edit button click
    $(document).on("click", ".edit", function () {

        /*td: nth - child(2)*/
        /*$(this).parents("tr").find("td:not(:last-child)").each(function () {*/
        $(this).parents("tr").find("td:nth-child(2)").each(function () {
            $(this).html('<input type="text" class="form-control" value="' + $(this).text() + '">');
        });
        $(this).parents("tr").find(".add, .edit").toggle();
        $(".add-new").attr("disabled", "disabled");
        $(".btnSubmit").attr("disabled", "disabled");
    });



    // Delete row on delete button click
    $(document).on("click", ".delete", function () {
        debugger;
        $(this).parents("tr").remove();
        $(".add-new").removeAttr("disabled");

        var rowCount = $('table.optionTable tbody tr').length;
        if (rowCount > 0) {
            $(".btnSubmit").removeAttr("disabled");
        } else {
            $(".btnSubmit").attr("disabled", "disabled");
        }

    });
});


</script>
@{
ViewBag.Title=“Soru Listesi”;
}
索鲁·奥卢图尔马
Sil”;
},
“可订购”:错误,
“可搜索”:错误,
“宽度”:“150px”
}
],
“语言”:{
“空表”:
“我的朋友们,我的朋友们,我的朋友们,我的朋友们,我的朋友们,我的朋友们。”
}
});
});
函数getDateString(日期){
var dateObj=新日期(parseInt(Date.substr(6));
让year=dateObj.getFullYear();
让month=(1+dateObj.getMonth()).toString().padStart(2,'0');
let day=dateObj.getDate().toString().padStart(2,'0');
返回日+'/'+月+'/'+年;
};
函数PopupForm(url){
var formDiv=$('');
$.get(url)
.完成(功能(响应){
html(回应);
Popup=formDiv.dialog({
自动打开:对,
可调整大小:正确,
标题:“Soru Detay”,
莫代尔:是的,
高度:“自动”,
宽度:“700”,
关闭:函数(){
对话框('destroy').remove();
}
});
});
}
函数提交表单(表单){
event.preventDefault();
if(form.checkValidity()==false){
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
var问题={};
question.questionId=$('#questionId').val();
question.questionName=$('#questionName').val();
var options=新数组();
$(“#问题表TBODY TR”)。每个(函数(){
var行=$(此);
var选项={};
option.optionId=row.find(“TD”).eq(0.html();
option.optionName=row.find(“TD”).eq(1.html();
option.questionId=0;
option.isActive=true;
option.status=true;
选项。推送(选项);
});
问题.选项=选项;
question.responses=新数组();
$.ajax({
类型:“POST”,
url:form.action,
数据:JSON.stringify(问题),
contentType:“应用程序/json”,
成功:功能(数据){
if(data.success){
弹出对话框(“关闭”);
dataTable.ajax.reload();
$.notify(data.message,
{
全球定位:“顶级中心”,
类名:“成功”,
showAnimation:“slideDown”,
差距:1000
});
}
},
错误:功能(请求、错误){
},
完成:功能(数据){
}
});
}
函数重置窗体(窗体){
弹出对话框(“关闭”);
返回false;
}
函数删除(id){
如果(确认('Bu soruyu silmek istediğden emin Misiz?')){
$.ajax({
类型:“POST”,
url:'@url.Action(“删除”,“问题”)/'+id,
成功:功能(数据){
if(data.success){
dataTable.ajax.reload();
$.notify(data.message,
{
类名:“成功”,
全球定位:“顶级中心”,
标题:“巴阿里里”
});
}
}
});
}
}
}
AddOrEdit.cshtml

@{
ViewBag.Title = "Soru Listesi";
}

<h2>Soru Oluşturma</h2>
<a class="btn btn-success" style="margin-bottom: 10px" 
onclick="PopupForm('@Url.Action("AddOrEdit","Question")')"><i class="fa fa-plus"></i> Yeni Soru 
Oluştur</a>
<table id="questionTable" class="table table-striped table-bordered accent-blue" style="width: 100%">
<thead>
    <tr>
        <th>Soru No</th>
        <th>Soru Adı</th>
        <th>Oluşturma Tarihi</th>
        <th>Güncelleme Tarihi</th>
        <th>Güncelle/Sil</th>
    </tr>
</thead>
</table>
<link href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />



@section Scripts{
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap4.min.js"></script>

<script>


    var Popup, dataTable;
    $(document).ready(function () {

        dataTable = $("#questionTable").DataTable({
            "ajax": {
                "url": "/Question/GetData",
                "type": "GET",
                "datatype": "json"
            },
            "columnDefs": [
                { targets: 2 }
            ],
            "scrollX": true,
            "scrollY": "auto",
            "columns": [
                { "data": "QuestionId" },
                { "data": "QuestionName" },
                {
                    "data": "CreatedDate",
                    "render": function (data) { return getDateString(data); }
                },
                {
                    "data": "UpdatedDate",
                    "render": function (data) { return getDateString(data); }
                },
                {
                    "data": "QuestionId",
                    "render": function (data) {
                        return "<a class='btn btn-primary btn-sm' onclick=PopupForm('@Url.Action("AddOrEdit", "Question")/" +
                            data +
                            "')><i class='fa fa-pencil'></i> Güncelle</a><a class='btn btn-danger btn-sm' style='margin-left:5px' onclick=Delete(" +
                            data +
                            ")><i class='fa fa-trash'></i> Sil</a>";
                    },
                    "orderable": false,
                    "searchable": false,
                    "width": "150px"
                }
            ],
            "language": {
                "emptyTable":
                    "Soru bulunamadı, lütfen <b>Yeni Soru Oluştur</b> butonuna tıklayarak yeni soru oluşturunuz. "
            }
        });
    });


    function getDateString(date) {
        var dateObj = new Date(parseInt(date.substr(6)));
        let year = dateObj.getFullYear();
        let month = (1 + dateObj.getMonth()).toString().padStart(2, '0');
        let day = dateObj.getDate().toString().padStart(2, '0');
        return day + '/' + month + '/' + year;
    };


    function PopupForm(url) {
        var formDiv = $('<div/>');
        $.get(url)
            .done(function (response) {
                formDiv.html(response);
                Popup = formDiv.dialog({
                    autoOpen: true,
                    resizable: true,
                    title: 'Soru Detay',
                    modal: true,
                    height: 'auto',
                    width: '700',
                    close: function () {
                        Popup.dialog('destroy').remove();
                    }

                });
            });
    }

    function SubmitForm(form) {
        event.preventDefault();
        if (form.checkValidity() === false) {
            event.preventDefault();
            event.stopPropagation();
        }
        form.classList.add('was-validated');

        var question = {};
        question.questionId = $('#QuestionId').val();
        question.questionName = $('#QuestionName').val();
        var options = new Array();
        $("#questionForm TBODY TR").each(function () {
            var row = $(this);
            var option = {};
            option.optionId = row.find("TD").eq(0).html();
            option.optionName = row.find("TD").eq(1).html();
            option.questionId = 0;
            option.isActive = true;
            option.status = true;
            options.push(option);
        });

        question.options = options;
        question.responses = new Array();
        $.ajax({
            type: "POST",
            url: form.action,
            data: JSON.stringify(question),
            contentType: "application/json",
            success: function (data) {
                if (data.success) {
                    Popup.dialog('close');
                    dataTable.ajax.reload();
                    $.notify(data.message,
                        {
                            globalPosition: "top center",
                            className: "success",
                            showAnimation: "slideDown",
                            gap: 1000
                        });
                }
            },
            error: function (req, err) {
            },
            complete: function (data) {
            }
        });
    }



    function ResetForm(form) {
        Popup.dialog('close');
        return false;
    }

    function Delete(id) {
        if (confirm('Bu soruyu silmek istediğinizden emin misiniz?')) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("Delete", "Question")/' + id,
                success: function (data) {
                    if (data.success) {
                        dataTable.ajax.reload();
                        $.notify(data.message,
                            {
                                className: "success",
                                globalPosition: "top center",
                                title: "BAŞARILI"
                            });
                    }
                }

            });
        }
    }

</script>
}
@using MerinosSurvey.Models
@model Questions
@{
 Layout = null;
}

@using (Html.BeginForm("AddOrEdit", "Question", FormMethod.Post, new { @class = "needs-validation", 
novalidate = "true", onsubmit = "return SubmitForm(this)", onreset = "return ResetForm(this)", id = 
"questionForm" }))
{
<div class="form-group row">
    @Html.Label("QuestionId", "Soru No", new { @class = "col-form-label col-md-3" })
    <div class="col-md-9">
        @Html.TextBoxFor(model => model.QuestionId, new { @readonly = "readonly", @class = "form-control" })

    </div>
</div>
<div class="form-group row">
    @Html.Label("QuestionName", "Soru Adı", new { @class = "col-form-label col-md-3" })
    <div class="col-md-9">
        @Html.EditorFor(model => model.QuestionName, new { htmlAttributes = new { @class = "form-control", required = "true" } })
        <div class="valid-feedback"><i class="fa fa-check">Süpersin</i></div>
        <div class="invalid-feedback "><i class="fa fa-times">Soru adı zorunludur.</i></div>
    </div>
</div>


@*<div class="form-group row">
        @Html.LabelFor(model => model.CreatedDate, new { @class = "form-control-label col-md-3"})
        <div class="col-md-9">
            @Html.EditorFor(model => model.CreatedDate, "{0:yyyy-MM-dd}", new { htmlAttributes = new { @class = "form-control", type = "date", @readonly = "readonly",required="false" } })

        </div>
    </div>*@


<div class="table-wrapper form-group table-responsive-md">
    <div class="table-title">
        <div class="form-group row">
            <div class="col-md-9">Seçenekler</div>
            <div class="col-md-3">
                <button type="button" class="btn btn-success add-new" style="margin-bottom: 10px"><i class="fa fa-plus"></i>Seçenek Ekle</button>
            </div>
        </div>
    </div>
    <table class="table optionTable">
        <thead>
            <tr>
                <th scope="col">Seçenek Id</th>
                <th scope="col">Seçenek Adı</th>
                <th scope="col">Güncelle/Sil</th>
            </tr>

        </thead>
        <tbody>
            @foreach (Options options in Model.Options)
                {
                    <tr>
                        <td>@options.OptionId</td>
                        <td>@options.OptionName</td>
                        <td>
                            <a class="add btn btn-primary btn-sm" title="Add" data-toggle="tooltip"><i class="fa fa-check">Onayla</i></a>
                            <a class="edit btn btn-secondary btn-sm" title="Edit" data-toggle="tooltip"><i class="fa fa-pencil">Güncelle</i></a>
                            <a class="delete btn-danger btn-sm" title="Delete" data-toggle="tooltip"><i class="fa fa-trash">Sil</i></a>
                        </td>
                    </tr>
                }
        </tbody>
    </table>
</div>


<div class="form-group row">

    <button type="submit" class="btn btn-primary btnSubmit" style="margin-bottom: 10px"><i class="fa fa-save"></i>Kaydet</button>
    <button type="reset" class="btn btn-secondary" style="margin-bottom: 10px" ><i class="fa fa-trash"></i>İptal</button>

</div>
}
<script>
$(document).ready(function () {
    $('[data-toggle="tooltip"]').tooltip();
    //var actions = $("table.optionTable td:last-child").html();

    var actions =
        ' <a class="add btn btn-primary btn-sm" title="Add" data-toggle="tooltip"><i class="fa fa-check">Onayla</i></a>' +
        '<a class="edit btn btn-secondary btn-sm" title="Edit" data-toggle="tooltip"><i class="fa fa-pencil">Güncelle</i></a>' +
        '<a class="delete btn-danger btn-sm" title="Delete" data-toggle="tooltip"><i class="fa fa-trash">Sil</i></a>';

    // Append table with add row form on add new button click
    $(".add-new").click(function () {
        debugger;
        $(this).attr("disabled", "disabled");
        $(".btnSubmit").attr("disabled", "disabled");
        var index = $("table.optionTable tbody tr:last-child").index();
        var row = '<tr>' +
            '<td>0</td>' +
            '<td><input type="text" class="form-control" name="optionName" id="optionName"></td>' +
            '<td>' + actions + '</td>' +
        '</tr>';
        $("table.optionTable").append(row);
        $("table.optionTable tbody tr").eq(index + 1).find(".add, .edit").toggle();
        $('[data-toggle="tooltip"]').tooltip();
    });



    // Add row on add button click
    $(document).on("click", ".add", function () {
        var empty = false;
        var input = $(this).parents("tr").find('input[type="text"]');
        input.each(function () {
            if (!$(this).val().trim()) {
                $(this).addClass("error");
                empty = true;
            } else {
                $(this).removeClass("error");
            }
        });
        $(this).parents("tr").find(".error").first().focus();
        if (!empty) {
            input.each(function () {
                $(this).parent("td").html($(this).val().trim());
            });
            $(this).parents("tr").find(".add, .edit").toggle();
            $(".add-new").removeAttr("disabled");
            $(".btnSubmit").removeAttr("disabled");

        }
    });

    // Edit row on edit button click
    $(document).on("click", ".edit", function () {

        /*td: nth - child(2)*/
        /*$(this).parents("tr").find("td:not(:last-child)").each(function () {*/
        $(this).parents("tr").find("td:nth-child(2)").each(function () {
            $(this).html('<input type="text" class="form-control" value="' + $(this).text() + '">');
        });
        $(this).parents("tr").find(".add, .edit").toggle();
        $(".add-new").attr("disabled", "disabled");
        $(".btnSubmit").attr("disabled", "disabled");
    });



    // Delete row on delete button click
    $(document).on("click", ".delete", function () {
        debugger;
        $(this).parents("tr").remove();
        $(".add-new").removeAttr("disabled");

        var rowCount = $('table.optionTable tbody tr').length;
        if (rowCount > 0) {
            $(".btnSubmit").removeAttr("disabled");
        } else {
            $(".btnSubmit").attr("disabled", "disabled");
        }

    });
});


</script>
@使用MerinosSurvey.Models
@典型问题
@{
布局=空;
}
@使用(Html.BeginForm(“AddOrEdit”,“Question”,FormMethod.Post,new{@class=”需要验证“,
novalidate=“true”,onsubmit=“return SubmitForm(this)”,onreset=“return ResetForm(this)”,id=
“问题表”})
{
@Label(“QuestionId”,“Soru No”,新的{@class=“col form Label col-md-3”})
@Html.TextBoxFor(model=>model.QuestionId,新的{@readonly=“readonly”,@class=“form control”})
@Label(“QuestionName”、“Soru Adı”、新的{@class=“col form Label col-md-3”})
@EditorFor(model=>model.QuestionName,new{htmlAttributes=new{@class=“form control”,required=“true”})
苏佩辛
索鲁·阿德·祖鲁鲁德。
@*
@LabelFor(model=>model.CreatedDate,新的{@class=“formcontrollabel col-md-3”})
@EditorFor(model=>model.CreatedDate,“{0:yyyy-MM-dd}”,new{htmlAttributes=new{@class=“form-control”,type=“date”,@readonly=“readonly”,required=“false”})
*@
塞内克勒
塞涅克埃克尔
塞涅克岛
Seçenek Adı
甘塞尔/西尔