开发者

Html.RenderAction cannot find action in controller in MVC2 for invalid ModelState

I have a PersonController and a View named "Add" inside of my Person folder in Views.

The Add view is taking in a title, first name, last name, and phone number. The title is a drop down list with pre-populated values. To get this drop down list, I call

<% Html.RenderAction("Titles", "Person");

When that Action is called, it returns a PartialView. The PartialView is the drop down list of the pre-configured titles.

Scenario:

I have two controller actions named "Add" (one get, and one post). On the HttpGet, it loads a blank form essentially, with the drop down list of titles, empty textboxes, etc. When the user clicks the upload button it calls the "Add" HttpPost. Inside of this action, I do some validation checking, making sure they filled out the required fields, etc. If the fields are blank, I add an error to the ModelState:

if(string.IsNullOrEmpty(firstName))
{
     ModelState.AddModelError("person", "Person first name is required.");
}

If the modelstate is not valid, i return the View, so the user can see the validation error messages.

The Action gets rendered correctly as long as the ModelState is valid, however, if there is an error and I add an error to the ModelState and return the View from the HttpPost action, an HttpException gets thrown开发者_Python百科 on the view of:

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

Informing me that an action named "Titles" cannot be found on "Person" controller. Obviously I know it is there, for it executed just fine before any errors were in the ModelState.

Any ideas?


The child action will be called using the same HTTP method as the main action that was first called.

Therefore, I am assuming you have [HttpGet] tagged onto your /Person/Titles action. If you remove this, it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜