Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Milos 6 posts 97 karma points
    Jun 28, 2018 @ 07:20
    Milos
    0

    MVC partial view renders without master page

    Hi, I am creating an umbraco mvc page that has a template that renders a partial view with 2 dropdown lists and a google map. When i load the page it has the master template with a partial view and it shows everything fine.

    When i select an item from the dropdown list i pass the value to the controler and return to the partial view other data. The problem is that the return of the partial view shows only the partial view without the master template.

    This is the code in the controller that fires when the page is loaded for the first time and this shows everything:

            public ActionResult RenderForm()
        {
            MapFunction MF = new MapFunction ();
    
            MF=SetDropDown();
            MF.JSON= SetMarkers();
    
    
            return PartialView(Partial_View_Folder + "_MapFunction .cshtml", MF);
        }
    

    This is the code that fires when the dropdown is selected:

            public ActionResult ChangeATM(MapFunction mapFunction)
        {
            MapFunction MF = new MapFunction ();
    
    
            mapFunction= ddlATMChange(mapFunction.PTT.ToString());
            MF = SetDropDown();
    
            mapFunction.Branch = MF.Branch;
            mapFunction.ATM = MF.ATM;
    
            return PartialView(Partial_View_Folder + "_MapFunction.cshtml", mapFunction);
    
        }
    

    My partial view code with the ddl:

                    @using (Html.BeginUmbracoForm("ChangeATM", "MapFunction", FormMethod.Post))
                {
                    @Html.DropDownListFor(m => m.PTT, Model.Branch, "Chose...", new { onchange = "this.form.submit();" })
                }
    

    I just want to refresh the partial view without loosing my master page and with new date.

    Thank you!

  • MuirisOG 382 posts 1284 karma points
    Aug 01, 2018 @ 10:28
    MuirisOG
    0

    Hi Milos

    I want to do something similar... did you find a solution?

    I have data coming from a database all working using a partial view. However, if I to display a detail page, I only get the partial view.

    Is there a solution for this (AJAX or otherwise)?

    Thanks

    Muiris

  • Milos 6 posts 97 karma points
    Aug 01, 2018 @ 11:04
    Milos
    101

    Yes i found the solution.

    The problem was the BeginUmbracoForm in the PartialView.

    I changed it to:

     @using (Ajax.BeginForm("ChangeATM", "MapFunction", null, new AjaxOptions
            {
                HttpMethod = "Post",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "Parent"
            }))
            {
                @Html.DropDownListFor(m => m.PTT, Model.Branch, "Choose...", new { onchange = "$(this.form).submit();", id = "use-ajax1" })
            }
    

    The problem was the BeginUmbracoForm in the PartialView.

    I changed it to:

         @using (Ajax.BeginForm("ChangeATM", "MapFunction", null, new AjaxOptions
            {
                HttpMethod = "Post",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "Parent"
            }))
            {
                @Html.DropDownListFor(m => m.PTT, Model.Branch, "Choose...", new { onchange = "$(this.form).submit();", id = "use-ajax1" })
            }
    

    Also you need to add the folowing script to the master page:

     <script type="text/javascript">
    $(document).on("change", ".use-ajax1", function (e) {
        e.preventDefault();
        var form = $(this).closest('form');
        $(form).submit();
    });</script
    

    Here is the link to the tutorial that helped me a lot: Submiting with ajax

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Aug 01, 2018 @ 13:02
    Paul Seal
    1

    I was about to give the same answer and link to my post :D

  • MuirisOG 382 posts 1284 karma points
    Aug 01, 2018 @ 13:04
    MuirisOG
    0

    This is exactly what I was after, thank you very much.

    I had implemented an accordion show/collapse style list so I could do it all on one page, but this would not be ideal for every solution.

    (I find codeshare.co.uk to be a really useful resource).

    Thanks again,

    Muiris

Please Sign in or register to post replies

Write your reply to:

Draft