ASP.NET MVC 4 - Redirect after Modal Save using Child Action

前端 未结 1 710
迷失自我
迷失自我 2021-02-10 05:28

UPDATE - There are a lot of posts regarding the Child actions are not allowed to perform redirect actions on SO and ASP.NET forums. The

1条回答
  •  灰色年华
    2021-02-10 06:01

    Try this for your modal:

    
    

    And then in your controller, fix your GET method so it returns a partial view result

    //
    // GET: /Franchise/Create
    
    public PartialViewResult Create(int FranchiseSetId)
    {
        ViewBag.PossibleFranchiseSets = franchisesetRepository.All;
        var franchise = new Franchise { FranchiseSetId = FranchiseSetId };
        return PartialView(franchise);
    } 
    

    I've made a couple of assumptions in this fix.

    1. Your "Create" view is supposed to be a partial view that has all of your form inputs
    2. When you call @Html.Action("Create", "Franchise", new { FranchiseSetId = Model.FranchiseSetID }) you are wanting to render that partial view
    3. You're wanting the "Save Changes" link at the bottom of the modal to actually save your modal and not the "Create" button that is displayed

    If I've missed something let me know and I'll update my answer to try and provide a better solution.

    0 讨论(0)
提交回复
热议问题