所以我的视图包含一些操作链接和一个 javascript 方法,我想要的是在操作链接中调用我的脚本,这是我的脚本:
function deleteSubscriber(id)
{
var url = '/Subscribers/Delete/' + id;
$.ajax({
type: "delete",
url: url,
data: {},
datatype: 'json',
success: function (data) { alert(id); },
});
}
这是我的行动链接:
@Html.ActionLink("Delete", "Delete", new { id=//here i want to put my script },new { @class = "delete-logo" })
这是我的行动:
[HttpDelete,ActionName("delete")]
public ActionResult Delete(string id)
{
try
{
IEnumerable<Subscribe> list = from s in dbcontext.Subscribes select s;
foreach (var sb in list)
{
if (sb.cin == id)
{
dbcontext.Subscribes.Remove(sb);
}
}
dbcontext.SaveChanges();
return View("Index");
}
catch
{
return View();
}
}