2013-01-10 29 views
1

使用MVC 3如何在部分完成時更新div css以顯示完整圖像?

我有一個問答,有三個部分。包含問卷的頁面有「下一個」,「上一個」和「保存」按鈕?當我點擊這些按鈕中的任何一個時,如果它返回true,我想要一個名爲「Question/SectionComplete」的Action控制器的ajax調用。我想用顯示完整圖標的css更新菜單div。 任何人都可以幫助開始使用示例代碼?

回答

0
function onButtonClick(){ 
    var data = { myvar: 1 }; // your data to pass to action 
    $.getJSON('Question/SectionComplete', data, function(result){ 
     if(result) 
      $('#mymenudiv').css('background-image', 'yourImage'); //your styles here 
    }) 
} 

在控制器:

public ActionResult SectionComplete(int myvar) 
{ 
    // check condition 
    return Json(true, JsonRequestBehaviour.AllowGet); // you can return complex object instead 
} 
+0

謝謝你的幫助! – Chaka

+0

不客氣 – karaxuna

0

使用阿賈克斯方法的成功功能 - 文件在這裏 - http://api.jquery.com/jQuery.ajax/

$.ajax({ 
    url: '/Question/SectionComplete', 
    success: function(data) { 
     // add code here 
     // test for your response 
     // then use jquery selector to get element to be updated 
     // and use .html() to set element's new value 
    } 
}); 
相關問題