2011-11-01 100 views
2

我使用jQuery post方法用于执行服务器端操作重定向到ASP.NET MVC行动,方法不会返回视图

方法是:

function redirectToDraft() { 

    updateInboxGridAndCloseApproveDialog(); 
    $.post('/Personnel/AgendaApproveDocument'); 
    } 

将张贴到这一行动然后在行动,我需要重定向到另一个动作的另一个控制器这样的:

public ActionResult AgendaApproveDocument(int? id){ 

    return RedirectToAction("RelatedDocumentDraft", new RouteValueDictionary(
       new 
       { 
        controller = "RegisterLetter", 
        action = "RelatedDocumentDraft", 
        title = relatedDoc.Name, 
        factory = relatedDoc.DocumentFactory, 
        activityId = action.WorkItem.Id 
       })); 

} 

它的工作原理,并重定向到方法:

public ActionResult RelatedDocumentDraft(int?activityId, string factory, string title) 
    { 
    return View("~/Views/RegisterLetter/NewDraft.aspx"); 
    } 

我的问题是,它不返回到视图“NewDraft”

有什么东西错了吗?

+0

您是否尝试过调试以查看您是否真的可以在该位置查看? – Rob

+0

那么它被重新定向了哪个页面?或者你得到了什么回应? – Lamps

回答

3

在您的AJAX调用中,您尚未订阅成功回调,因此什么都不会发生。如果你想处理AJAX调用的结果,那你应该这样做:

$.post('/Personnel/AgendaApproveDocument', function(result) { 
    // the result variable here will contain the markup of the view  
    // so you could for example replace some portion of the DOM with it 
    // (assuming of course it is a partial view): 

    $('#foo').html(result); 
}); 
2

我认为你正在寻找RedirectToAction方法。检查John Sheehan的this answer

return RedirectToAction("Index", model); 

有关MSDN的更多信息。

+0

如果你完全阅读我的文章,你会发现我的问题是,我重定向的方法不会返回视图 – Adrakadabra

1

你正在为这个方法做一个AJAX帖子 - 它不会对响应做任何事情,除非你告诉它。为什么AJAX会将简单的表单提交更好的工作?

相关问题