Why action not found in my controller?

為{幸葍}努か 提交于 2019-12-24 04:49:07

问题


I have this code:

return RedirectToAction("Save", "RequestFinishedDocument",
                                new {requestId = requestFinished.Request_ID, requestFinishedId = requestFinished.ID});

And in my controller I have:

public class RequestFinishedDocumentController : Controller
{
    [HttpPost]
    public JsonResult Save(int requestId, int requestFinishedId)
    {
        //todo
    }
}

But on the RedirectToAction call I get the exception message: A public action method 'Save' was not found on controller 'SuiP.Controllers.RequestFinishedDocumentController'.

What's wrong?

Thank


回答1:


RedirectToAction performs a HTTP GET. Your action method only accepts a HTTP POST.




回答2:


Try changing it to:

public class RequestFinishedDocumentController : Controller
{
    [HttpGet]
    public JsonResult Save(int requestId, int requestFinishedId)
    {
        //todo
    }
}

and see if that works.



来源:https://stackoverflow.com/questions/6511786/why-action-not-found-in-my-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!