How can I make an MVC POST return me to the previous page?

后端 未结 3 1121
遥遥无期
遥遥无期 2021-01-14 00:41

I have the following action which is called from a screen with a list of records.

    [HttpPost]
    //[Authorize(Roles = \"admin\")]
    public ActionResul         


        
3条回答
  •  庸人自扰
    2021-01-14 01:36

    What you described is easily achieved using ajax calls. That way you perform whatever action you like and afterwards (on successful response), you can easily navigate from the current page, using javascript.

    If you POST to a page and in response you return the same view you receive with a GET request (index page), then some users might hit F5 to reload that index page and get a warning in the browser, which actually says it will send the POST request again. This is pretty confusing for users and not really user friendly (not to mention numerous concerns related to idem-potency of it).

    Although you don't like the redirect approach, because of the additional response, I guess, I should say that, in MVC, this is the correct way to do it, assuming you don't want to use ajax calls.

提交回复
热议问题