ASP.NET MVC: RedirectToAction with parameters to POST Action

前端 未结 2 1611
孤独总比滥情好
孤独总比滥情好 2020-11-30 05:18

This question has been asked here:

RedirectToAction with parameter

But what if I have two actions with the same name but different parameters? How do I redir

相关标签:
2条回答
  • 2020-11-30 05:33

    You are correct that you can call the method directly, but I would highly suggest that you rethink your architecture/implementation.

    The HTTP Protocol embraces the idea of safe and unsafe verbs. Safe verbs like GET are not suppose to modify the state of the server in any way, whilst Unsafe verbs like POST, PUT do modify state. By you GET calling the POST method you are violating this principle since it is not inconceivable that your POST is going to be modifying state.

    Also best practice dictates that you should limits the verbs on all your actions so if the first 'Terms' method is meant as a GET, then also add the HttpGet attribute to it to prevent other Http actions from being accepted by the server for the action.

    0 讨论(0)
  • 2020-11-30 05:43

    Nevermind guys, actually I could just call the method directly instead of using RedirectToAction like so:

    return Terms(month, year, deposit, total);
    

    Instead of:

    return RedirectToAction("Terms", {month, year, deposit, total});
    
    0 讨论(0)
提交回复
热议问题