Copied to clipboard

Flag this post as spam?

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


  • Graham Davis 104 posts 359 karma points
    Aug 14, 2017 @ 06:09
    Graham Davis
    0

    How to pass data to view from an external source

    Our company supports the Real Estate industry and I an trying to create a page in Umbraco that load the details of the listing from an id passed in the url. I have tried several examples so far and am lost as to what the missing piece is. The data is retrieved from an external MLS database via a REST API.

    I have a custom route that looks like this:

    RouteTable.Routes.MapRoute(
               name: "PropertyDetails",
               url: "real-estate/{description}/{address}/{propertyID}",
               defaults: new { controller = "Property", action = "Index", propertyID = UrlParameter.Optional }
           );
    

    For my Controller, I have tried RenderMvcController, SurfaceController, and PluginController. It currently looks like this:

    public class PropertyController : Umbraco.Web.Mvc.PluginController
    
    {
        public PropertyController()
            : this(UmbracoContext.Current)
        {
        }
    
        public PropertyController(UmbracoContext umbracoContext)
            : base(umbracoContext)
        {
        }
    
        public ActionResult Index(string propertyID)
        {
            dbzBest.Models.PropertyDetails p = new dbzBest.Models.PropertyDetails();
    
            umbraco.NodeFactory.Node node = umbraco.uQuery.GetNodesByName("real-estate").FirstOrDefault();
            IPublishedContent currentNode = Umbraco.Content(node.Id);
    
            p = zbdLibrary.GlobalFunctions.zbdAPI("property/GetDetails/" + propertyID).jsonToEntity<dbzBest.Models.PropertyDetails>();
    
    
            //***Using this line returns page as expected, but no info on the property.  I get null errors with out it.
            //return View("real-estate", CreateRenderModel(currentNode));
    
            //this line fails.  How do I pass this data to the view?
            return View("real-estate", p);
        }
    
        private RenderModel CreateRenderModel(IPublishedContent content)
        {
            var model = new RenderModel(content, CultureInfo.CurrentUICulture);
            //add an umbraco data token so the umbraco view engine executes
            RouteData.DataTokens["umbraco"] = model;
            return model;
        }
    }
    

    Can someone please tell me what I am missing?

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies