Asp.Net MVC : Execution of the child request failed. Please examine the InnerException for more information

爱⌒轻易说出口 提交于 2019-12-06 00:13:33

问题


I'm recieving the following error message,

A public action method 'RenderMenu' was not found on controller 'Web.Controllers.SiteController'.

However this action DOES exist and the controller does exist (As it work everywhere on the site) I looked at the inner exception.

Execution of the child request failed. Please examine the InnerException for more information.

(This is the inner exception...)

Stack Trace

at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func) at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)

Now, we have a website set-up with a dynamic menu system so we are using RenderAction() on a generic controller to build this menu system up.

<% Html.RenderAction("RenderMenu", "Site"); %>

This call is made from the MasterPage and it works fine until there was a validation error like so,

 [HttpPost]
        public ActionResult Register(UserModel UserToAdd)
        {
            if(!ModelState.IsValid)
            {
                return View(UserToAdd);
            }
            //Run some validation
            if (_UserService.DoesEmailExist(UserToAdd.EMail))
            {
                TempData["error"] = "Email Address Already in use!";
                return View(UserToAdd);
            }

            //Add the user

            TempData["info"] = "User Added - " + UserO.ID;
            return View("Success");
        }

It works fine when there this is a new user, but if someone enters an email that already exist we get the above error. THis RenderAction Method works all over the site (This is the first form we have added)

Any suggestions?


回答1:


Fixed:

The RenderAction() Method is below

        [HttpGet]
        public ActionResult RenderMenu()
        {
            //Do Stuff
        }

Removing the HttpGet Attribute has resolved the issue.

        public ActionResult RenderMenu()
        {
            //Do Stuff
        }

Would love to know why?




回答2:


This is because your parent request is an [HttpPost], and the child request operates in the same verb as the parent. If your method is marked as [HttpGet], it will not respond to [HttpPost] requests. Hitting the action directly through your browser works because that is a GET. Hitting the action as a child action in the context of a POST will not work.



来源:https://stackoverflow.com/questions/3211919/asp-net-mvc-execution-of-the-child-request-failed-please-examine-the-innerexc

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