,所以我有我的觀點,即包含一些actionlinks和JavaScript的方法,我想是把我的腳本在ActionLink的,這是我的腳本:如何在actionlink mvc 4中調用javascript函數?
function deleteSubscriber(id)
{
var url = '/Subscribers/Delete/' + id;
$.ajax({
type: "delete",
url: url,
data: {},
datatype: 'json',
success: function (data) { alert(id); },
});
}
這是我的ActionLink:
@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();
}
}
感謝您的回覆,我只是想知道如何獲得id並將其傳遞給腳本! – Mohammadov 2013-04-27 15:49:20
Id是否會成爲您的刪除按鈕的ID? – PSL 2013-04-27 15:50:18
如果有意義,請參閱我的更新。 – PSL 2013-04-27 15:53:12