【发布时间】:2013-02-28 21:10:27
【问题描述】:
这是我认为的 ASP MVC 代码。它触发到控制器并传递assetId和relationshipContext:
@Html.ActionLink("Archive", "Archive", new { assetId = Model.ID, relationshipContext = assetTypeRelation.RelationshipContextID }, new { @class = "btn btn-mini btn-warning", id = "btnArchive" })
我想通过这个 HTML.ActionLink 使用 Ajax,但有点困惑。这是我开始使用的 jQuery。基本上我只需要这个 actionlink 来将assetId 和relationshipContext 传递给我的assetcontroller 中的Archive 方法。
$('#btnArchive').click(function(){
$.ajax({
url: '@Url.Action("Archive", "Archive")',
type: 'POST',
dataType: 'json',
data: {
assetId: $(this).attr("assetId"),
relationshipContext: $(this).attr("relationshipContext"),
},
success: function(){
alert("success")
},
error: function () {
alert("error")
},
});
【问题讨论】:
-
我不认识顶部的那种语言。我做了一个谷歌搜索,发现它是 asp.net 的一部分,特别是 mvc 部分。我添加了 asp.net-mvc 标记,但您可能想在代码中添加一些解释。
-
您想混合使用服务器端和客户端代码。
-
感谢您添加附加标签,我更新了问题的正文。
标签: jquery ajax asp.net-mvc html.actionlink