在我的项目添加,删除和编辑功能不起作用

时间:2016-03-28 11:36:58

标签: javascript

我正在使用java脚本语言进行crud操作,但它无法正常工作。 我已经尝试了100%,但它不起作用。请帮帮我。谢谢 这是我的观点代码:

@model PagedList.IPagedList<TraderCartMvc.Models.UserAdmin>
@using PagedList.Mvc;

@{           
    ViewBag.Title = "Login";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
    int CountID = 1;
    int CountID1 = 1;
    int CountID2 = 1;
}

<html>
<head>
    <title>Administrator Panel</title>
</head>
<body>


    <div class="portlet box yellow">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-cogs"></i>Admins
            </div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
            </div>
        </div>

        @using (Html.BeginForm()){    
        <tr><td> <span> Search:</span></td><td><input type="text", placeholder="Search Admin Name Here" class="form-control" style="width:190px" id="searchid" /></td><td>
                     <input type="button" value="Search" onclick="search()" /></td></tr>
        } 

        <div class="portlet-body">
            <div class="clearfix"></div>
            <table class="table table-bordered" cellpadding="0" cellspacing="0" width="90%">
                <thead>
                    <tr>
                        <th>No
                        </th>
                        <th>Staff Name
                        </th>
                        <th>Email
                        </th>
                        <th>Password
                        </th>

                        <th style="padding: 1.6%;">Action
                        </th>
                    </tr>
                </thead>



                @foreach (var item in Model)
                {
                    <tbody>
                        <tr>

                            <input type="hidden" value="@item.ID" id="ID_@CountID" style="margin:5px 0;" />
                            <td>

                                <span style="margin: 5px 0;">@CountID</span>
                            </td>
                            <td>

                                <input type="text" class="form-control" value="@item.Name" id="Name_@CountID" style="margin:5px 0;" />

                            </td>
                            <td>
                                <input type="text" class="form-control" value="@item.Email" id="Email_@CountID" style="margin:5px 0;" />

                            </td>
                            <td>
                                <input type="password" class="form-control" value="@item.Password" id="Pass_@CountID" style="margin:5px 0;" />

                            </td>

                            <td>
                                <a href="#">
                                    <span class="btn btn-primary" title="Save the Changes" id="@CountID">Edit</span></a>
                                @*<span class="fa fa-edit editit" title="Save the Changes" id="@CountID"></span>*@
                               <a href="#">
                                    <span class="btn btn-danger" title="Delete this Record" id="@CountID1">Delete</span>
                          @*  <span class="fa fa-trash-o deleteit" title="Delete this Record" id="@CountID1"></span>*@
                                </a>

                            </td>

                        </tr>

                    </tbody>
                    CountID++;
                    CountID1++;
                    CountID2++;
                }

                @if (ViewBag.count == 0)
                { 
                    <tr>
                        <td colspan="10" style="color: red; font-weight: bold; background: #d7d7d7; font-family: sans-serif; font-size: large">
                            <p style="text-align: center">There is no record to display</p>
                        </td>
                    </tr>
                }

                <tr>
                    <td></td>
                    <td>

                        <input class="form-control" type="text" value="" id="NameNew" style="margin: 5px 0;" />

                    </td>
                    <td>
                        <input class="form-control" type="text" value="" id="EmailNew" style="margin: 5px 0;" />

                    </td>
                    <td>
                        <input class="form-control" type="password" value="" id="PassNew" style="margin: 5px 0;" />

                    </td>


                    <td><a href="#">
                        @*<div class="form-control" style="margin: 1px -3px; width: 28px; height: 26px; padding-left: 7px;">*@
                            <span class="btn btn-primary" title="Add New Administrator" id="addit">ADD</span>
                           @*<span class="fa fa-plus" title="Add New Administrator" id="addit"></span>*@
                       @* </div>*@
                        </a>

                    </td>

                </tr>

            </table>
        </div>
        <div class="pagedList">
        @Html.PagedListPager(Model, page => Url.Action("Index", new { page }), PagedListRenderOptions.PageNumbersOnly)
    </div>
    </div>


    </body>
</html>
    <script type="text/javascript">

        $("#addit").click(function (e1) {

            var Name = $("#NameNew").val();
            var Dev_Email = $("#EmailNew").val();
            var Dev_Pass = $("#PassNew").val();


            if (Name == "" || Dev_Email == "" || Dev_Pass == "") {

                alert("Fill the Empty Field");
            }
            else {

                window.location.href = "/Admin/Staff/Add_Staff/?Name=" + Name + '&Email=' + Dev_Email + '&Pass=' + Dev_Pass;
            }
        })


        $(".editit").click(function (e1) {

            var Name = $("#Name_" + this.id).val();
            var Dev_Email = $("#Email_" + this.id).val();
            var Dev_Pass = $("#Pass_" + this.id).val();
            var ID = $("#ID_" + this.id).val();

         if (Name == "" || Dev_Email == "" || Dev_Pass == "") {

                alert("Fill the Empty Field");
            }
            else {

                window.location.href = "/Admin/Staff/Update_Staff/?Name=" + Name + '&Email=' + Dev_Email + '&Pass=' + Dev_Pass + '&id=' + ID;
            }
        })

        $(".deleteit").click(function (e1) {
            var ID = $("#ID_" + this.id).val();
            var OK = confirm("Are you Sure you want to Delete?");
            if (OK) {
                window.location.href = "/Admin/Staff/Delete_Staff/?ID=" + ID;
            }
            else {
            }
            })

        function search() {
            var search = $("#searchid").val();
            if (search == "") {
                alert("Please fill the empty Field");
                return false;
            }
            window.location.href = '/Admin/Staff/Index?&searchString=' + search;
        }
    </script>

     <script src="~/Content/angular.min.js"></script>

1 个答案:

答案 0 :(得分:0)

您必须在关闭正文之前移动脚本:

  <!-- put your js code here -->
 </body>
</html>

在html标记之外使其无效。