使用 ajax 从数据库 Mvc 中的 table 中删除行
Using ajax to delete row from table in database Mvc
我想使用 ajax 从数据库中删除行,删除后刷新包含所有数据的部分视图
<a class="fa fa-times" href="javascript:DeleteCurrency(@item.CountryID)" title="Delete"></a>
**这是将调用 javascript 函数的锚 link **
function DeleteCurrency(CountryID) {
var Con = confirm("are you sure ?");
if (Con == true) {
$.ajax({
url: "@Url.Action("DeleteCountry","Main")" + CountryID,
type: 'Delete',
async: true,
processData: false,
cache: false,
sucess: function (data) {
alert(dtat);
},
error: function (xhr) {
alert('error');
}
});
}
}
**这是我用于删除的控制器方法**
[HttpDelete]
public ActionResult DeleteCountry(int CountryID)
{
try
{
Country count = db.Countrys.Find(CountryID);
db.Countrys.Remove(count);
db.SaveChanges();
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return PartialView("_DetailsOfData", AllCountries);
}
catch (Exception)
{
ViewBag.AlreadyAdded = "يوجد محافظات تابعه لهذه الدوله لا يمكن مسحها";
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return View("AddCountry", AllCountries);
}
}
当我点击锚点时 link 确认消息弹出窗口(你确定吗?)当点击确定时一直输入错误我想知道错误是什么
CountryID 应在 ajax 数据属性中单独传递。例如:
function DeleteCurrency(CountryID) {
var Con = confirm("are you sure ?");
if (Con == true) {
$.ajax({
url: "@Url.Action("DeleteCountry","Main")" ,
type: 'Delete',
data: {
CountryID: CountryID,
},
dataType: "text/html",
async: true,
cache: false,
sucess: function (data) {
alert(dtat);
},
error: function (xhr) {
alert('error');
}
});
}
}
我想使用 ajax 从数据库中删除行,删除后刷新包含所有数据的部分视图
<a class="fa fa-times" href="javascript:DeleteCurrency(@item.CountryID)" title="Delete"></a>
**这是将调用 javascript 函数的锚 link **
function DeleteCurrency(CountryID) {
var Con = confirm("are you sure ?");
if (Con == true) {
$.ajax({
url: "@Url.Action("DeleteCountry","Main")" + CountryID,
type: 'Delete',
async: true,
processData: false,
cache: false,
sucess: function (data) {
alert(dtat);
},
error: function (xhr) {
alert('error');
}
});
}
}
**这是我用于删除的控制器方法**
[HttpDelete]
public ActionResult DeleteCountry(int CountryID)
{
try
{
Country count = db.Countrys.Find(CountryID);
db.Countrys.Remove(count);
db.SaveChanges();
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return PartialView("_DetailsOfData", AllCountries);
}
catch (Exception)
{
ViewBag.AlreadyAdded = "يوجد محافظات تابعه لهذه الدوله لا يمكن مسحها";
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return View("AddCountry", AllCountries);
}
}
当我点击锚点时 link 确认消息弹出窗口(你确定吗?)当点击确定时一直输入错误我想知道错误是什么
CountryID 应在 ajax 数据属性中单独传递。例如:
function DeleteCurrency(CountryID) {
var Con = confirm("are you sure ?");
if (Con == true) {
$.ajax({
url: "@Url.Action("DeleteCountry","Main")" ,
type: 'Delete',
data: {
CountryID: CountryID,
},
dataType: "text/html",
async: true,
cache: false,
sucess: function (data) {
alert(dtat);
},
error: function (xhr) {
alert('error');
}
});
}
}