ASP.NET MVC Partial view ajax post?

后端 未结 2 1422
小蘑菇
小蘑菇 2020-12-02 19:25

Index.html (View)

@Html.Action(\"_AddCategory\", \"Categories\")
2条回答
  •  没有蜡笔的小新
    2020-12-02 20:05

    The ajax call you made should not be able to redirect the whole page. It returns data to your asynchronous call only. If you want to perform a redirect, i

    the javascript way to redirect is with window.location

    So your ajax call should look like this:

    
    

    In you action method, instead of returning a partial or redirect, return Json(true);

    public ActionResult _AddCategory(CategoriesViewModel viewModel)
    {
        if(//success)
        {
            return Json(true);
        }
        else
        {
            return Json(false);
        }
    }
    

提交回复
热议问题