child actions are not allowed to perform redirect actions. partial view RRS feed

  • Question

  • I'm using ASP .NET MVC 5

    I'm trying to use Create view with the index view to show the created item in the same page. For that I'm using _CreateCategory as the partial view and I added following to the index view

    {Html.RenderAction("Create", Model);}

    My controller's get and post methods as follows for the Create

    [HttpGet] public ActionResult Create() { return PartialView("_CreateCategory",new Inventory.Models.Category()); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include="Id,Description")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return RedirectToAction( "Index"); } return PartialView(category); }

    My index method as follows

    public ActionResult Index()
            return View(db.Categories.ToList());

    I didn't do any changes to the partial view. I'm getting error "

    child actions are not allowed to perform redirect action

    . I tried many ways to overcome this. But no luck yet.

    • Moved by Mike Danes Wednesday, April 15, 2015 11:00 AM asp.net related
    Wednesday, April 15, 2015 10:27 AM


All replies