ASP.NET MVC - How to call void controller method without leaving the view?

前端 未结 7 2212
北恋
北恋 2020-12-01 11:51

Question background:

I am implementing some basic \'shopping cart\' logic to an MVC app. Currently when I click a link - denoted as \'Add T

相关标签:
7条回答
  • 2020-12-01 12:53

    I was struggling with this and couldn't get it working with ajax.

    Eventually got a working solution by making my controller method return type ActionResult rather than void and returning a RedirectToAction() and inputting the action relating to the view I wanted to remain on when calling the controller method.

    public ActionResult Method()
            {
                // logic
    
                return RedirectToAction("ActionName");
            }
    
    0 讨论(0)
提交回复
热议问题