0

我嘗試了一些東西。我爲我的英語提前道歉。是不是我想要PartialViewResult的方式

我的動作代碼;

public PartialViewResult showProduct() 
{ 

    var query = db.Categories.Where((c) => c.CategoryID == 4); 
    return PartialView("_EditCategory",query); 
} 

我的視圖代碼:

@using (Ajax.BeginForm(
    "showProduct", 
    new AjaxOptions 
    { 
     HttpMethod = "GET", 
     InsertionMode = InsertionMode.InsertAfter, 
     UpdateTargetId = "result" 
    })) 
    { 
     <input type="submit" value="Get" /> 
    } 
    <div id="result"> 
    </div> 

當我按下提交按鈕(這值獲得)返回結果,但在像http://localhost:57616/Home/showProduct另一個頁面,但我想回導致索引頁格。

任何人都可以幫助我嗎?

回答

1

那麼,如何處理這個自己是這樣的:

$(document).ready(function() { 
var options = { 
    target: "#mytargetdiv", 
    url: '@Url.Action("Edit", "IceCream")', 
}; 

$("#editIceCreamForm").submit(function() { 
    $(this).ajaxSubmit(options); 
    return false; 
} 

// other stuff 

}); 
在其他地方

,在這裏我想做就地東西編輯我會做這樣的事情:

<input type="button" id="someid" value="Edit" data-someid="@Model.SomeId"/> 

,然後一些Ajax像這樣:

$(function() { 
    $("#someid".click(function() { 
     var theId = $(this).data('someid'); 
     $.ajax({ 
     type: "GET", 
     data: "id=" + theId, 
     url: '@Url.Action("Edit", "Something")', 
     dataType: "html", 
     success: function (result) { 
      $('#targetdiv').html(result); 
     } 
     }); 
    }); 
}); 

因此,如果您對使用jQuery並且想要使用MS Ajax的東西不感興趣,那麼您是否在頁面上包含了MicrosoftAjax.js和MicrosoftMvcAjax.js文件?如果你沒有這些,我相信會發生什麼,它只是默認(非Ajax)提交。

+0

我不想用javascript :( –

+0

請參閱我在答案底部添加的註釋。 – itsmatt

相關問題