GuitarRich / sitecore.react

A ReactJS module for building Sitecore components with React
MIT License
36 stars 22 forks source link

Error rendering controller #5

Closed Beatusvir closed 7 years ago

Beatusvir commented 7 years ago

Hey guys

I'm trying to get this working, after creating a React Controller Rendering and setting the jsx file / controller setting. I add the rendering to a page and I get this: image

The controller is just this, I guess the problem is from PageTitle rendering name; thats what I was doing following the this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sitecore.React.Mvc.Controllers;
using Sitecore.Feature.PageContent.Model;

namespace Sitecore.Feature.PageContent.Controllers
{

    public class PageContentController : Controller
    {
        // GET: PageContent
        public ActionResult PageTitle()
        {
            var viewModel = new PageTitleViewModel
            {
                Title = "Some title",
                Summary = "Summary for page"
            };
            return this.React("PageTitle", viewModel);
        }
    }
}

This is the sitecore rendering image

GuitarRich commented 7 years ago

It looks like your controller has not been registered with the IoC container. If you are on 8.2+ you need to make sure that all controllers are registered with the container using a configurator class. See this post for more details on that: https://kamsar.net/index.php/2016/08/Dependency-Injection-in-Sitecore-8-2/

Beatusvir commented 7 years ago

Thanks for your quick reply @GuitarRich , I'm more a react guy than a sitecore guy, and Sitecore is huge!!, checking it

GuitarRich commented 7 years ago

@Beatusvir did you get this sorted?

Beatusvir commented 7 years ago

@GuitarRich hey Richard, I started fresh from a new Habitat instance to make sure I wasnt doing something weird and this error is gone. Still couldnt get the controller to render my react component. I'll post the new question soon.

PS: off topic, I'm from Venezuela, last few weeks were crazy here so I had to run to Panama for a few days to see how everything would come out and just got home, so I can resume work for a now at least

Beatusvir commented 7 years ago

Edit 2: So I finally got this to render; I had to edit the views/index.js (where we export every component) to this (not the .default at the end): image

~~Edit: Ok some progress, right now I'm getting this: Minified error~~

~~Alright, I was able to try this again. I deleted my rendering and created a new one, copied the jsx file to the website folder (not sure if its needed since the script is already on place) and the error is now this:~~

Message: The model item passed into the dictionary is of type *** but this dictionary requires a model item of type 'Sitecore.Mvc.Presentation.RenderingModel'.

hmm... it looks like is trying to render the cshtml view, like the normal view I'm currently using, same name