简体   繁体   中英

Redirecting to action in ASP.NET MVC, method wont return the view

I am using jquery post method for executing a server side action

the method is :

 function redirectToDraft() {

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

it will post to this action and then in the action i need to redirect to another action on the other controller like this :

 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
                }));

}

it works and redirect to the method:

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

my problem is that it doesnt return to the view "NewDraft"

is there any thing wrong?

In your AJAX call you haven't subscribed to the success callback, so nothing will happen. If you wanted to handle the results of an AJAX call, that's what you should do:

$.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);
});

I think you're looking for the RedirectToAction method. Check this answer from John Sheehan.

return RedirectToAction("Index", model);

Additional information on MSDN .

You're doing an AJAX post to this method - it won't do anything with the response unless you tell it to. Why the AJAX, would a simple form submit work better?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM