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
    Sep 24, 2016 @ 12:08
    Robert
    0

    Inherit from RenderModel

    Hi, there; I am developing a view that use ajax call from a view

    public class MyViewModel : RenderModel
    {
    
        public MyViewModel ()
            : base(Umbraco.Web.UmbracoContext.Current.PublishedContentRequest.PublishedContent)
        {
    
        }
    

    ... ... ... }

    When my code steps into the constructor calling "base(Umbraco.Web......)", the program just stuck there, never return, looks be "swallowed"

    Can someone help what is happening here?

    THX.

    Robert

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 05, 2016 @ 21:56
    Alex Skrypnyk
    0

    Hi Robert,

    Did you find solution?

    Thanks,

    Alex

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Oct 06, 2016 @ 06:20
    David Brendel
    1

    Hi Robert,

    depending on what should happen on your ajax call I would suggest to not use the RenderMvcController which is returning a model that inherit from RenderModel. Instead I would suggest to use a SurfaceController for your ajax request and then return a normal model that don't inherit the RenderModel.

    Regards David

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 06, 2016 @ 09:23
    Alex Skrypnyk
    0

    Thanks David. Agree with you - don't need to use RenderMvcController for AJAX, another solution will be UmbracoApiController.

    I think UmbracoApiController is the best for working with AJAX requests.

    Thanks,

    Alex

  • Robert 21 posts 122 karma points
    Oct 06, 2016 @ 09:54
    Robert
    0

    Hi, David and Alex; Thanks for your response. Yes, I fixed the issue. I used SurfaceController as David said. "stuck" is because "Umbraco.Web.UmbracoContext.Current.PublishedContentRequest" is null. For some reasons there is no "null" exception thrown. Still cannot figure out why it is "null". Just have a new case that "PublishedContentRequest" is null. Please have a look my latest post regarding this issue if you have interest.

    Cheers Robert.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 06, 2016 @ 10:46
    Alex Skrypnyk
    0

    Hi Robert,

    Can you share your code?

    Are you trying to return binded view from controller?

    Thanks,

    Alex

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

    Sure. Yes, I am trying to return a binded view:

    I am now using SurfaceController.

    Navigation:

          <li><a href="@Url.SurfaceAction("MySiteList", "RoomSurface", new { countryID = 1 })">I have site</a></li>  
    

    Action:

        public ActionResult MySiteList()
        {
    
            IHaveSiteViewModel mySite = new IHaveSiteViewModel();
            mySite.MySitesList = _repository.GetMySiteList(_userId);
            return View("IHaveSite", mySite);
        }
    
        Where: In IHaveSiteViewModel I have:
        public IHaveSiteViewModel()
            : base(Umbraco.Web.UmbracoContext.Current.PublishedContentRequest.PublishedContent)
        {
    
        }
    

    My Index View:

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

    }

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 07, 2016 @ 12:35
    Alex Skrypnyk
    0

    Robert, maybe you can use json for returning data and bind it via JS?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 07, 2016 @ 12:58
    Alex Skrypnyk
    0

    I would use JSON via AJAX, its faster and better in any case.

    But you have to write some piece of code.

    Thanks,

    Alex

  • Robert 21 posts 122 karma points
    Oct 08, 2016 @ 03:45
    Robert
    0

    HI, Alex; I agree Jason is quicker. But I don't think this is the problem: PublishedContentRequest = null. I think I don't use the controller and RenderModel properly.

    Cheers Robert.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Oct 07, 2016 @ 13:50
    David Brendel
    1

    Hi Robert,

    I think there are some missconceptions here.

    First of all when you are using a surface controller then the model shouldn't inherit from render model. Thats only necessary when you are using a RenderMvcController.

    Second the view you are returning in your surface controller should not have a layout page. It should only be a partial.

    Returning a json from the controller only makes sense if you want to change everything dynamically. When it should be called on the first time the page loads a view with a model should be fine.

    Regards David

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 07, 2016 @ 13:54
    Alex Skrypnyk
    0

    Hi David,

    Thanks, agree with you with all except JSON )) I think all data returning via AJAX is better to transfer with JSON.

    But sometimes it's ok to use partial views. For example when rendering is hard operation and we need to use serverside caching of html.

    Thanks,

    Alex

  • Robert 21 posts 122 karma points
    Oct 08, 2016 @ 03:40
    Robert
    0

    HI, David; Yes, I think you are right. I should not use SurfaceController. My HomePage is a "registered" Umbraco Page created in back office. I use RenderMvcController. The second page is not from Umbraco, it is created by my self (except the layout page that inherits from UmbracoTemplatePage). I think that why "PublishedContentRequest" is null. If I create a content in back office as my second page then I believe this will fix the issue. I get around this issue by NOT inheriting my view model from RenderModel and have a different layout. This looks more like a traditional MVC page.

    Cheers, Robert

Please Sign in or register to post replies

Write your reply to:

Draft