Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

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

C#
[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

C#
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900