Copied to clipboard

Flag this post as spam?

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


  • Robert 21 posts 122 karma points
    Oct 06, 2016 @ 10:14
    Robert
    0

    "PublishedContentRequest" is null

    HI, there; I am having an ajax call when clicking a button in my Index view to return a partial view.

    When the action method runs my view model (inhertis from RenderModel):

     public RoomDetailViewModel()
            : base(Umbraco.Web.UmbracoContext.Current.PublishedContentRequest.PublishedContent)
        {
         .....
        }
    

    it shows "PublishedContentRequest" is null.

    Does someone have similar issue and have a solution to this?

    thx.

    Cheers Robert

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 06, 2016 @ 10:31
    Alex Skrypnyk
    0

    Hi Robert,

    Are you using RenderMvcController with AJAX? Can you share your code?

    It's not the best way to perform AJAX requests, UmbracoApiController is specially for that case.

    Thanks,

    Alex

  • Robert 21 posts 122 karma points
    Oct 07, 2016 @ 10:06
    Robert
    0

    HI, Alex; NO, I am using SurfaceController with ajax. View:

     @inherits     Umbraco.Web.Mvc.UmbracoViewPage<IHaveSiteViewModel>
    @{ 
          Layout = "_Layout.cshtml";
    }
    @using (Html.BeginForm())
    {
     <div id="mySiteList">
         @Html.Partial("MySiteList", Model)
     </div>
    }
    

    Partial View:

     @inherits Umbraco.Web.Mvc.UmbracoViewPage<IHaveSiteViewModel>
     @foreach (var site in Model.MySitesList)
     {
        <div class="media-object stack-for-small">
            <div class="media-object-section">
                <a href="@Url.SurfaceAction("EditRoomDetail", "RoomSurface", new { siteID = site.SiteID })">
                    <img class="thumbnail" src="">
                </a>
            </div>
    
        </div>
    
    }
    <button type="button" class="button" id="addNew">Add New</button>
    

    ajax call:

     $("#addNew").click(function () {
               $.ajax({
                url: '/umbraco/surface/RoomSurface/IHaveSite',
                type: 'post',
                datatype: 'json',
                processData: false,
                success: function (resultData) {
                    if (resultData != null) {
                       $("#mySite").html(resultData);
                    }
                }
            })
        })
    

    Action Method:

      public ActionResult IHaveSite()
        {
            .....
            IHaveSiteViewModel mySite = null;
    
             mySite = new IHaveSiteViewModel();}
    
        }
    
     Where: In IHaveSiteViewModel:
    
       public IHaveSiteViewModel()
            : base(Umbraco.Web.UmbracoContext.Current.PublishedContentRequest.PublishedContent)
        {
    
        }
    

    Cheers Robert.

  • Isaac Abramowitz 3 posts 73 karma points
    Jul 25, 2019 @ 15:49
    Isaac Abramowitz
    0

    Hi Robert, I'm having the exact same issue. Have you found a solution by any chance?

Please Sign in or register to post replies

Write your reply to:

Draft