我是新使用Ajax,我試圖調用從Ajax方法後動作像重定向使用Ajax POST
$(".buttonSelection").click(function() {
selectedId = $(this).parents('tr:first').children('td:first').children('input:first').attr('value');
$.ajax({
// Call MaSelection action method
url: "/DemandeLocation/MaSelectionOffre",
data: { id: selectedId },
type: 'Post',
success: function (msg) {
window.location.replace('@Url.Content("~/DemandeLocation/MaSelectionOffre")');
},
error: function (xhr) {
alert("something seems wrong");
}
});
});
我的帖子方法去與成功,但不是redirectin我到MaSelection查看它返回我調用方法的第一個視圖,所以我試圖在我的ajax方法中放入一個「成功」片段,並將位置替換爲「Ma選擇」視圖,但我知道該視圖丟失了該ID,因此它變成了null,我怎麼能用Ajax做到這一點,
這裏我的貼子動作了解更多詳情
[HttpPost]
[Authorize(Roles = "Locataire")]
public ActionResult MaSelectionOffre(string id)
{
int DemandeLocationGetbyId = Convert.ToInt32(id);
var selectionOffre = db.SelectionOffreLocationSet.Where(model => model.DemandeLocationPublication_ID == DemandeLocationGetbyId).ToList();
return View("MaSelectionOffre", selectionOffre);
}
難道你不能只通過selectedId與目標url你重定向到? –