How to call MVC Action using Jquery AJAX and then submit form in MVC?

后端 未结 3 1974
暗喜
暗喜 2020-12-14 19:00

On my MVC View I have button:


When I click this button I need c

3条回答
  •  隐瞒了意图╮
    2020-12-14 19:30

    Your C# action "Save" doesn't execute because your AJAX url is pointing to "/Home/SaveDetailedInfo" and not "/Home/Save".

    To call another action from within an action you can maybe try this solution: link

    Here's another better solution : link

    [HttpPost]
    public ActionResult SaveDetailedInfo(Option[] Options)
    {
        return Json(new { status = "Success", message = "Success" });
    }
    
    [HttpPost]
    public ActionResult Save()
    { 
        return RedirectToAction("SaveDetailedInfo", Options);
    }
    

    AJAX:

    Initial ajax call url: "/Home/Save"
    on success callback: 
       make new ajax url: "/Home/SaveDetailedInfo"
    

提交回复
热议问题