[英]Get Mvc3 Ajax.ActionLink replaced data with Jquery?
我有一个@Ajax.ActionLink
替换他自己的包装器,另一个内容也有@Ajax.ActionLink
,它将第一个html内容返回给包装器。 它是部分的链接,取代了它的自我和反之亦然。 我的问题是当我想要一些aditional functionaliti点击ActionLink时,我的Jquery返回旧的部分,已经点击的那个,而不是新的,在firebug中我清楚地看到我的新元素,但是无法触及它们,我试过, OnSuccess和OnComplete,但没有成功! 有任何想法吗?
这是一个例子:
视图
index.cshtml
<div id="box">
@Html.Partial("_PartialOne")
</div>
_ PartialOne.cshtml
@Ajax.ActionLink("Get partial two", "getPartial2", "Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new { @class="first"}
)
<div id="testBox1">Hello, I am partial 1</div>
_ PartialTwo.cshtml
@Ajax.ActionLink("Get partial one", "getPartial1","Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new { @class="second"}
)
<div id="testBox2">Hello there this is partial 2</div>
CONTROLLER
HomeController.cs
public PartialViewResult getPartial1()
{
return PartialView("_PartialOne");
}
public PartialViewResult getPartial2()
{
return PartialView("_PartialTwo");
}
JS
$("#box a.first").live('click', function () {
//how to fetch new data, that was filled with getPartial2()
console.log($(this).parent().children());
//this returns [a.first, div#testBox1]
// and I need [a.second, div#testBox2]
});
如何选择返回的数据让我们说必要的子串?
编辑
使用OnComplete =“function”
视图
@Ajax.ActionLink("Get partial two", "getPartial2", "Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
OnComplete = "getNewData"
},
new { @class="first"}
)
<div id="testBox1">Hello, I am partial 1</div>
JS
function getNewData()
{
console.log($(this));
//this returns [Object] of ajax call, niether
// $(this).parent/s(), or $(this).children() is posible
}
如何选择调用此ajax的元素的子元素?
我想我不是100%你想要的,但我想也许你的问题是缓存。 如果您在GET请求中添加唯一参数,您是否得到了您正在寻找的结果?
@Ajax.ActionLink("Get partial two", "getPartial2", "Home", new { aparam = DateTime.Now.Ticks },
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
OnComplete = "completeGetThing"
},
new { @class="first"}
)
<div id="testBox1">Hello, I am partial 1</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.