R – Asp.Net Mvc – Render partial view – Manage errors

asp.net-mvcrenderpartial

I got an aspx page call ListArticles with the following code :

<% Html.RenderPartial("Create", new Models.Article()); %>

Create is a partial view (Create.ascx).

In my controller, I got something like this :

if (!ModelState.IsValid) { 
     return View();
}

So the problem is that the view generated by return View(); doesn't render the good view. It's should render the ListArticles view while highlighting errors in the Create partial view but it's only show the Create.ascx view.

Is there a way to handle that ?

Best Answer

I suggest for this situation which you embed a form in your View which need to post and show the errors you use Ajax.BeginForm instead of partial views . Partial Views is more suitable for showing scenarios.