I am using ASP.NET MVC and trying to use HTML.RenderAction to render partial View, inside Main View, but getting error as "Child actions are not allowed to perform redirect actions."
Here is my .cshtml code
<div class="col-lg-3">
@{Html.RenderAction("GetLeftMenu", new { category = Model.Category });}
</div>
<div class="col-lg-9">
@Html.Raw(Model.TutorialText)
</div>
</div>
and Here is my C# controller code
[AllowAnonymous]
public ActionResult GetLeftMenu(string category)
{
using (var context = new ModelEntities())
{
var List = context.Tuts.Where(a => a.Category == category && a.IsActive == true).Select(a=> new TutorialLeftMenu { Title= a.TutorialTitle, Id= a.Id, URL=a.TutorialURL, Order=Convert.ToInt32(a.TutOrder),MainHeader=a.MainHeader, Category=a.Category }).OrderBy(a=>a.Order).ToList();
return PartialView(List);
}
}
how can I resolve this error?
You cannot send PartialView like this, as this is not allowed because MVC has already started Rendering the View to the browser (client). So the MVC Frameworks blocks this, because the client already receives data (html). As long as the rendering is in progress you not able to redirect in your child view.
Means:
You can return RedirectToAction instead (if needed)
OR
This can also happen if you have [RequireHttps]
attribute on the Controller, and a child action was called from a different controller.
So RequireHttps
can cause issue.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly