MVC Player error

Topics: MVC, Troubleshooting
Jul 13, 2011 at 5:31 PM

Hello all,

I'm getting an error with the MVC player and could use a little help.

Error: The controller for path '/Home' was not found or does not implement IController.
Error details:
Failed to get value for function 'Composite.AspNet.MvcPlayer.Render'
Exception has been thrown by the target of an invocation.
The controller for path '/Home' was not found or does not implement IController.

I've added the mvc player to a page template, and am a little lost from there.

If I have a view, say "Views/Home/Index.cshtml", what do i need to create in the Content section of the admin to be able to see the view as the root page of the site http://localhost:36861/ ?

Thanks for any tips...

Jul 14, 2011 at 7:34 AM

Hello,

What version of C1 do you use?

Jul 14, 2011 at 9:15 AM

Hi kcwebmonkey

It seems that you haven't created the controller for your Home view.

If you are using C1 v 2.1.1 - which is a stable version MVC Player works with, please read http://docs.composite.net/C1/ASP-NET/HelloWorldMVC.aspx (it has a couple of examples)
For more samples, please also read our blog posts on MVC:
http://community.composite.net/C1/Blog.aspx/MVC

The MVC Player kind of hooks up an existing MVC solution to your C1 website. It implies that you normally put the player (the function) on a dedicated page on your C1 website and access your entire MVC solution from that page. On v 2.1.1 it will work like: http://localhost:36861/MVC.aspx/Home ...


At the moment the MVC Player won't work on the latest "2.1.3 beta" builds because of some breaking changes in C1 :(. This will be fixed in the package itself and new version will be published online.

/Vitaly

Jul 14, 2011 at 9:20 AM
Edited Jul 14, 2011 at 9:23 AM

XSLT Function Composite.AspNet.MvcPlayer should be added to the page content. You  specified  "/Home" as path, so  make sure that controller with name HomeController.cs exists

As example check this article  -  Composite-C1-support-ASPNET-MVC-3-and-Razor

Jul 14, 2011 at 4:39 PM
Edited Jul 14, 2011 at 4:41 PM

thanks everyone for your input.

What version of C1 do you use?

Composite C1 VS2010_2.1.4113.99_ReleaseBuild_20110406.1

It seems that you haven't created the controller for your Home view.

I have indeed created both the controller and the view, see visual studio screenshot http://dl.dropbox.com/u/10795793/screenshot.jpg

I tried both adding the MvcPlayer function to a template and to a content page... both give me the same error.

The MVC Player kind of hooks up an existing MVC solution to your C1 website. It implies that you normally put the player (the function) on a dedicated page on your C1 website and access your entire MVC solution from that page. On v 2.1.1 it will work like: http://localhost:36861/MVC.aspx/Home ...

I guess i don't quite understand how the MVC Player works.  Are you saying that I am supposed to add the MVC player to the home page and then access the entire site from that page?  does this mean i am no longer using the CMS' ability to edit pages and placeholder sections?  Is there any documentation on this that i can read up on?

Thanks!

Jul 14, 2011 at 6:25 PM

Im tempted to ask how you did expect the MVC player to work? What is your goal? Do you want to be able to create the whole template for a page in MVC instead of xslt or Webforms Masterpages, or do you just prefer writing html generating functions in Razor instead of ie. xslt?

If the former is the case, you would need to hijack the whole templating behavior of C1. Its really not that hard to do and the Webforms Masterpages templating is done by me like this. I also did a pure MVC rendering implementation a few months back which sounds like what you're looking for. I haven't been updating the code for it since way back since it was a for-fun-weekend-project and i don't use MVC myself... not yet anyway. But you can look for inspiration here

Content route for mapping a page url to a controller http://compositec1contrib.codeplex.com/SourceControl/changeset/view/68476#1133199
A base controller that holds a reference to the page being requested and ensures user validation http://compositec1contrib.codeplex.com/SourceControl/changeset/view/68476#1133203
An html helper for writing out content of placeholders and C1 functions http://compositec1contrib.codeplex.com/SourceControl/changeset/view/68476#1133198 

Jul 14, 2011 at 7:06 PM

Im tempted to ask how you did expect the MVC player to work? What is your goal? Do you want to be able to create the whole template for a page in MVC instead of xslt or Webforms Masterpages, or do you just prefer writing html generating functions in Razor instead of ie. xslt?

No, I don't need the whole template to be in MVC, i just need to be able to talk to my ActionResults and JsonResults.

I currently have a home page with URL Title "Index" and i've added the MVC player just below the <body> tag

<html xmlns="http://www.w3.org/1999/xhtml">
  <head></head>
  <body>
    <f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Composite.AspNet.MvcPlayer">
      <f:param name="Path" value="/Home" />
    </f:function>

and i do have a HomeController.cs with an Index actionresult in the App_Code folder, yet i am still getting the error... getting a little frustrating as i can't move past this and get my ActionResults to work. 

Jul 15, 2011 at 7:47 AM

Looks like all configured correctly and should work.

Could you check this file ~\App_Code\Composite\AspNet\MvcPlayer\Route.cs and show the code from  method RegisterRoutes() ?

Jul 15, 2011 at 8:00 AM
Edited Jul 15, 2011 at 8:02 AM

Hi kcwebmonkey,

I am trying to figure out what is different in your environment that might account for the error. Could you please answer a few questions?

  1. What is your OS?
  2. What is your web server? (IIS6, IIS7 Integrated mode, IIS7 Classic mode, IIS Express (via WebMatrix), ASP.NET Dev Server aka Cassini (Via Visual Studio))
  3. When you ran the C1 setup wizard, what website template did you select?
  4. Are there any packages (except for MVC Player) you have installed on your website?
  5. How did you create your HomeController.cs file? (a. In Visual Studion: Add New Item etc etc; b. Uploaded an existing file via the C1 Admin console: System perspective > /App_Code > Upload etc etc; c. Copied an existing file to App_Code in your file manager, e.g. Windows Explorer)
  6. Could you also make a screenshot of, or copy here, the contents of your /Views/Home/Index.cs (if it is not super secret, of course :))?

Thanks in advance

/Vitaly

 

Jul 18, 2011 at 3:37 PM
Inna wrote:

Looks like all configured correctly and should work.

Could you check this file ~\App_Code\Composite\AspNet\MvcPlayer\Route.cs and show the code from  method RegisterRoutes() ?

 

using System.Web.Routing;
using System.Web.Mvc;
using Composite.Core.Application;

namespace Composite.AspNet.MvcPlayer
{
    /// <summary>
    /// Initializer for Routes
    /// </summary>
    [ApplicationStartup]
    public class Route
    {
        public static void OnBeforeInitialize()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

        public static void OnInitialized()
        {
        }

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        private static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("Composite/{*pathInfo}");
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                    "Default",
                    "{controller}/{action}/{id}",
                    new { action = "Index", id = "" }
            );
        }
    }
}
Jul 18, 2011 at 3:41 PM
Edited Jul 18, 2011 at 3:41 PM
wysocki wrote:

Hi kcwebmonkey,

I am trying to figure out what is different in your environment that might account for the error. Could you please answer a few questions?

  1. What is your OS?
  2. What is your web server? (IIS6, IIS7 Integrated mode, IIS7 Classic mode, IIS Express (via WebMatrix), ASP.NET Dev Server aka Cassini (Via Visual Studio))
  3. When you ran the C1 setup wizard, what website template did you select?
  4. Are there any packages (except for MVC Player) you have installed on your website?
  5. How did you create your HomeController.cs file? (a. In Visual Studion: Add New Item etc etc; b. Uploaded an existing file via the C1 Admin console: System perspective > /App_Code > Upload etc etc; c. Copied an existing file to App_Code in your file manager, e.g. Windows Explorer)
  6. Could you also make a screenshot of, or copy here, the contents of your /Views/Home/Index.cs (if it is not super secret, of course :))?

Thanks in advance

/Vitaly

 

1. Win XP
2. VS 2010 web server
3. Barebones site
4. SQL server data provider
5. right click > add > new file
6. my index file right now is just empty except for the word "testing"

Jul 18, 2011 at 8:00 PM
Edited Jul 18, 2011 at 8:12 PM

Hi, kcwebmonkey

I was able to reproduce the problem on VS Web Server. I deleted my HomeController.cs from App_Code and then added it again  and then got this error.

I am not sure what cause the problem but I managed to fix it only by deleting  asp.net temporary files at  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\

So, try to stop development web server  and then  delete asp.net temporary files, then run your site again.

If this will not help, try to run your site in IIS web server.

 

Jul 18, 2011 at 9:07 PM
Edited Jul 18, 2011 at 9:52 PM

I deleted the temporary files and was receiving an error but after building the solution the MVC Player is now working.

Is the page's URL title determining which ActionResult is being displayed or how exactly is the MVC Player doing this? Also, If I'm wanting MVC on every page, what is the best way to implement it into a template?

Jul 19, 2011 at 8:21 AM

>> Is the page's URL title determining which ActionResult is being displayed or how exactly is the MVC Player doing this?

No, the URL title  is not the case.

As you know ASP.NET MVC uses URL routing system that enables you to define URL mapping rules (map incoming URLs to the application and route them so that the right Controller and Action method are invoked)

NOTE: Routes must be registered in ~\App_Code\Composite\AspNet\MvcPlayer\Route.cs instead of Global.asax.

If you look at this file you will see that default rule is defined:

 

routes.MapRoute(
                    "Default",
                    "{controller}/{action}/{id}",
                    new { action = "Index", id = "" }
            );

 

This routing rule above indicates that the ASP.MVC framework should by default map URLs to Controllers using a "[controller]/[action]/[id]" pattern when determining which Controller class to instantiate, and which Action method to invoke. (Default action is Index)

When you insert MVC player function to the page you should specify the Start path, for example "/Home", or "/Home/Index". What does this mean? -

When you request the page that contains MVC player function (e.g. with Path="/Home" ) and its URL doesn't contain any path to determine controller/action, ( e.g. http://localhost/test.aspx ) then MVC player will rewrite URL to the path specified in its Path parameter (to http://localhost/test.aspx/Home) then MVC framework will determine Home controller and Index action method.

When you request, for example URL like http://localhost/test.aspx/SomeOtherController/SomeOtherAction, then MVC framework will determine SomeOtherController controller and SomeOtherAction action method.

So, MVC player uses the path information (after <page url title>.aspx) to initialize MVC routing mechanism and if this path is empty, then MVC player will use path specified in its Path parameter.

Jul 19, 2011 at 5:50 PM

thanks for the detailed reply.

Oct 11, 2011 at 2:02 PM

Inna,

I tried that, and indeed what Url.Action("JsonTest", "MVCDemo", new { id = 995511 }) generates is .aspx/MVCDemo/JsonTest/995511 but when I enter this in the browser, I get the page, but when I enter mydomain/MVCDemo/JsonTest/995511 I receive my ActionResult.