简体   繁体   English

获取Mvc3 Ajax.ActionLink用Jquery替换数据?

[英]Get Mvc3 Ajax.ActionLink replaced data with Jquery?

I have an @Ajax.ActionLink that replaces his own wrapper, with another content that also has @Ajax.ActionLink , that returns first html content to wrapper. 我有一个@Ajax.ActionLink替换他自己的包装器,另一个内容也有@Ajax.ActionLink ,它将第一个html内容返回给包装器。 It's link to partial that replaces it's self and viceversa. 它是部分的链接,取代了它的自我和反之亦然。 My problem is that when i want some aditional functionaliti on click to ActionLink, my Jquery returns old partial, the one that has been click, and not the new, in firebug i clearly see my new elements, but cannot reach them, i tried, OnSuccess and OnComplete, but didnt succed! 我的问题是当我想要一些aditional functionaliti点击ActionLink时,我的Jquery返回旧的部分,已经点击的那个,而不是新的,在firebug中我清楚地看到我的新元素,但是无法触及它们,我试过, OnSuccess和OnComplete,但没有成功! Any ideas? 有任何想法吗?

Here's example: 这是一个例子:

VIEW 视图

index.cshtml index.cshtml

<div id="box">
    @Html.Partial("_PartialOne")
</div>

_ PartialOne.cshtml _ 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 _ 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 CONTROLLER

HomeController.cs HomeController.cs

public PartialViewResult getPartial1()
{
    return PartialView("_PartialOne");
}

public PartialViewResult getPartial2()
{
    return PartialView("_PartialTwo");
}

JS 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] 
});

How to select returned data to let's say substring if neccesary?? 如何选择返回的数据让我们说必要的子串?

EDIT 编辑

using OnComplete = "function" 使用OnComplete =“function”

VIEW 视图

@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 JS

function getNewData()
{
    console.log($(this));

    //this returns [Object] of ajax call, niether
   // $(this).parent/s(), or $(this).children() is posible

}

How to select children of element that called this ajax? 如何选择调用此ajax的元素的子元素?

I guess I am not 100% what you are looking for, but I think maybe your issue is caching. 我想我不是100%你想要的,但我想也许你的问题是缓存。 If you tack a unique parameter onto the GET request, do you get the result you are looking for? 如果您在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM