Copied to clipboard

Flag this post as spam?

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


  • Vanilson 28 posts 150 karma points
    Jul 02, 2016 @ 19:10
    Vanilson
    0

    IPublishedContent in a Partial View

    Hi guys, I´m trying to use IPublishedContent in a partial view and I´m having some problems. Here´s the code:

    I got one page that calls a partial view using ajax, the ajax call it´s working fine, I will just show the controller and the partial view code.

    Controller

        public ActionResult partialProducts()
        {
            return PartialView("Products");
        }
    

    Partial View

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
       var pageName = Model.Content.Name;
    }
    <h1>@pageName</h1>
    

    pageName it´s returning me Null, but I test a normal view and the code works fine, does anyone knows how to solve this problem.

    Best Regards

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 02, 2016 @ 22:19
    Alex Skrypnyk
    0

    Hi Vanilson,

    The problem with a context in ajax call.

    Are you using SurfaceController or just mvc controller?

    Thanks,

    Alex

  • Vanilson 28 posts 150 karma points
    Jul 02, 2016 @ 22:43
    Vanilson
    0

    Hi Alex, I´m using Surface Controller, here is the code of the ajax:

                $("#products").click(function () {
                $.ajax({
                    type: "GET",
                    url: "/Umbraco/Surface/ProductsSurface/partialProducts",
                    success: function (result) {
                        $(".content").html(result);
                    },
                    error: function(){
                        console.log("Error");
                    }
                });
            });
    

    Best Regards

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 03, 2016 @ 09:55
    Alex Skrypnyk
    0

    Hi Vanilson,

    As I understand problem is that Umbraco doesn't know on which page you are. Model.Content - it's CurrentPage, but when you get '/Umbraco/Surface/ProductsSurface/partialProducts' url via ajax Umbraco doesn't know what is CurrentPage. You have to help Umbraco to understand what page exactly you want to retrieve.

    Happy coding,

    Alex

  • Vanilson 28 posts 150 karma points
    Jul 03, 2016 @ 12:14
    Vanilson
    0

    Hi Alex, I guess that you´re right. I change the view that must call the partial view to this:

    <div class="content">
         @Html.Partial("Products")
    </div>
    

    And the @pageName give me the value of page that call the partial and not the value of the partial view.

    I´m insist on it because I pretend to get some values using IPublishedContent.

    Best Regards

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 03, 2016 @ 12:16
    Alex Skrypnyk
    0

    Vanilson, you can get your page by id and use it in partial view and even call via ajax.

    Was your problem solved?

    Best

  • Vanilson 28 posts 150 karma points
    Jul 05, 2016 @ 14:06
    Vanilson
    0

    Hi Alex, solve the problem using UmbracoHelper. Thank you for your help.

    Best Regards

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 05, 2016 @ 14:54
    Alex Skrypnyk
    100

    Great, can you mark solution solved?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft