【发布时间】:2014-06-16 10:02:24
【问题描述】:
我正在使用 ActionLink 和 ajax 调用将部分视图放在父页面中。问题是我的控制器和局部视图被调用了两次,在第二次调用时传递给动作的参数为空。
我尝试了两个版本的 ActionLink。一个人只调用一次控制器,但参数为空。第二次打了两个电话,第二次他们是空的
如何防止发送空参数的第二次调用,或者如果必须进行第二次调用,我该如何维持这些值?
这是进行两次调用的链接:
@Ajax.ActionLink(stdFName, "Action", "Controller", new { studentNumber = stdNum }, new AjaxOptions { UpdateTargetId = "theTimes", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }, new { @class = "studentName", id = "linkNo" + appendId.ToString() });
这是只调用一次但参数为空的链接
@Ajax.ActionLink(stdFName, "Action", "Controller", new AjaxOptions { UpdateTargetId = "theTimes", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" });
这是脚本:
$("a.studentName").on("click", function () {
var linkID = this.id;
var theProp = $(this).attr("href");
alert(theProp + linkID);
var equalPosition = theProp.indexOf("=");
var pram = theProp.substring(equalPosition + 1);
alert(pram);
var parms = { data: linkID };
$.ajax({
type: "GET",
url: "/Controller/Action",
data: parms,
dataType: "html",
success: function (data) {
$("theTimes").html(data);
}
});
});
【问题讨论】:
标签: javascript jquery asp.net asp.net-mvc-3