Copied to clipboard

Flag this post as spam?

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


  • Luyolo Mgodi 71 posts 120 karma points
    Aug 30, 2015 @ 22:46
    Luyolo Mgodi
    0

    Render view with data stored in Custom Tables

    Hi guys,

    I have this issue that I have been stuck on for a few days now. Here is my scenario: I have data stored in custom table and I need to get that data and display in a view. I had hijacked the HTTP request so that I could pass some parameter, and I got an error that the I am passing my custom Model, but a a model of type "RenderModel" is expected. I changed my custom Model to inherit from the class "RenderModel"

    Here is my code:

    Controller:

    public class AccommodationController : SurfaceController
    {
       [System.Web.Http.HttpGet]
        public ActionResult Index(int accommodationId)
       {
           var content = Umbraco.TypedContent(Config.HomeNode);
           return new GetAccomodationById<ActionResult>(content)
            {
                OnComplete = (model) => View("Accommodation", model),
                OnFailed = () => View("Error")
            }.Execute(accommodationId);
        }
    
    }
    

    Please note this line:

    var content = Umbraco.TypedContent(Config.HomeNode);
    

    I had just added that line so that I have "Umbraco" page that I can use when I initialize my Model.

    And here is my Model:

    public class SingleAccommodationViewModel : RenderModel
    {
        public SingleAccommodationViewModel(IPublishedContent content) : base(content) {}
    
        public int AccomodationId { get; set; }
    
        public string Name { get; set; } }
    

    Please note this line on my controller :

    var content = Umbraco.TypedContent(Config.HomeNode);
    

    I am implicitly getting the home page to pass to my Model constructor, because this in not an Umbraco Page, and for that reason it wont be found on the Umbraco Context. So I am passing the homepage so that I dont pass a null "iPublishedContent" object to my model. However I get a "Object reference not set to an instance of an object." error. Please help.

  • Luyolo Mgodi 71 posts 120 karma points
    Aug 31, 2015 @ 18:48
    Luyolo Mgodi
    0

    Anyone with any sort of help on this issue ?

Please Sign in or register to post replies

Write your reply to:

Draft