在我的项目中,添加、删除和编辑功能不起作用
In My Project Add, Delete and Edit function is not working
我正在使用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>
您必须在关闭正文之前移动脚本:
<!-- put your js code here -->
</body>
</html>
html标记外部使其无效。
相关文章:
- ACE编辑器正在删除模块,因为define是't一根绳子
- 如何从DOM中删除Aloha编辑器
- 如何删除包含内容可编辑跨度的整个跨度元素
- 如何从拼音编辑器中删除特殊字符
- 使用AJAX传递的数据编辑XML文件-正在删除XML数据
- 如何根据某些条件向可编辑的jquery数据表添加或删除按钮
- Rails Production-可以工作,但不能编辑/删除/创建记录
- 使部分内容可编辑,无法删除
- 如何使用jstree删除上下文菜单中的编辑选项
- X 可编辑:删除“.editable-unsaved”类
- 如何过滤对象内部深度堆叠的数据(并在之后编辑删除它)
- jTable条件显示隐藏基于数据所有者的编辑和删除按钮
- 表中的动态按钮用于使用Javascript(CodeIgniter)删除/编辑数据
- 如何隐藏剑道网格命令的编辑按钮或删除按钮
- php使用ajax生成html表,以应用用户操作,如删除、更新和编辑
- CodeMirror 删除编辑器实例
- 无法向我的程序添加删除/编辑功能
- 谷歌分析:从后台删除/编辑交易
- 删除编辑表元素
- 从SharePoint 2013列表中删除编辑或新建项目按钮