2012-08-17 54 views
0

實施例 - 在按鈕點擊是否有可能使一個呼叫到從在同一時間返回JSON(ID)的主視圖的局部視圖返回到主視圖

$('#btn').click(function() { 
    var flag = false; 
    var b; 
    $.ajax({ 
     type: 'GET', 
     url: '/Test/PV1/' + $('#Elements').val(), 
     data: null, 
     success: function (data) { 
      alert(data.pageID); 
     } 
    }); 
    return false; 
}); 

在控制器

public ActionResult PV1(int id) 
{ 
    //-- here i need to make a call to the partial view as well as return the pageID to the main view 
} 

是否可以撥打電話,從在同一時間返回JSON(ID)的主視圖的局部視圖返回到主視圖

+0

是的,它是MVC 3 – Soni 2012-08-17 13:27:10

回答

0

,你可以泡事件從您的局部到父( althoug h其通常不被認爲是最佳實踐)。

即。 在你的父母身上,有一個功能來設置ID爲某物。 然後在您的部分onSuccess中調用該函數。

例如。

父視圖

function doSomethingWithId(id){ 
    // do whatever you wanted to with the id now that its in the parent view 
} 

局部視圖

$('#btn').click(function() { 
var flag = false; 
var b; 
$.ajax({ 
    type: 'GET', 
    url: '/Test/PV1/' + $('#Elements').val(), 
    data: null, 
    success: function (data) { 
     doSomethingWithId(data.pageID); 
    } 
}); 
return false; 

});

+0

謝謝,這個解決方案爲我工作。 – Soni 2012-08-20 15:27:29