Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Dec 21, 2012 @ 14:35
    Lee
    0

    Surface Controller Not Working?

    I have the following 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using System.Web.Mvc;
    using MyProject.Core.Constants;
    using MyProject.Core.ViewModels;
    using Umbraco.Web.Models; using Umbraco.Web.Mvc; namespace ChilternThrustBore.Core.Controllers { public class ExampleController : SurfaceController { /// <summary> /// Example of calling an MVC route, you would use /// /umbraco/surface/{controllername}/{action}/{id} /// So this works if you put in /umbraco/surface/example /// </summary> /// <returns></returns> public ActionResult Index() { return Content("hello world"); } } }

    But when I try to browse to see the hello world via

     

    /umbraco/surface/example/

     

    I get the following error?

    Attempt by method 'MyProject.Core.Controllers.ExampleController.Index()' to access method 'System.Web.Mvc.Controller.Content(System.String)' failed.

    Any ideas? I can't see anything wrong with it? The controller is getting hit, but it throws this wobbly as soon as it hits this part?

    return Content("hello world");
  • Lee 1130 posts 3088 karma points
    Dec 21, 2012 @ 14:37
    Lee
    0

    Hmm can't edit the above post now

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 21, 2012 @ 14:39
    Dirk De Grave
    1

    Don't you need ExampleSurfaceController instead of ExampleController?

     

    /Dirk

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 21, 2012 @ 14:42
    Matt Brailsford
    0

    As Dirk said, if it follows the same rules as V5, it had to be suffixed ..SurfaceController

    Matt

  • Lee 1130 posts 3088 karma points
    Dec 21, 2012 @ 15:06
    Lee
    0

    No you can run it without being suffixed. This is a copy of a working 'play' solution and its all of a sudden not working on this one only? I'll keep tinkering.

  • Lee 1130 posts 3088 karma points
    Dec 21, 2012 @ 16:02
    Lee
    0

    Just to let you know. I'm a twat. Ignore the above. I had left the old binaries in the bin folder of the web project, so it was trying to load both. All working fine now.

    So for anyone reading this, you don't need to prefix 'SurfaceController' now like you did in v5. The above works just fine.

  • Stefan 3 posts 24 karma points
    Jan 02, 2013 @ 15:53
    Stefan
    0

    I was Trying the SurfaceController but got the same problem (version 4.11), I can't figure out wat the problem is

     

    Code

         public class HomeSurfaceController : SurfaceController
        {

            [ChildActionOnly]
            public ActionResult test()
            {
                return Content("Yep!");
            }

        }

     

    Error

    Attempt by method 'TestProject.Controllers.HomeSurfaceController.test()' to access method 'System.Web.Mvc.Controller.Content(System.String)' failed.

     The strange thing is when I just return a string instead of an ActionResult it works

     

      public class HomeSurfaceController : SurfaceController
        {

            [ChildActionOnly]
            public string test()
            {
                return "Yep~";
            }

        }

     

     

    ps (sorry for not posting the code in those codeblocks when i put them in the preformatted blocks its a mess)

  • jaygreasley 416 posts 403 karma points
    Jan 05, 2013 @ 22:55
    jaygreasley
    0

    I get the same error. 

    Lee, what binaries had you left in the bin directory? cheers

  • Lee 1130 posts 3088 karma points
    Jan 06, 2013 @ 09:19
    Lee
    0

    I had binaries left over from the project I copied this one from. Also check your project debug/bin folders. A clean solution simply does not get rid of all the old binaries if you are in the same position I am.

  • Edwin van Koppen 156 posts 270 karma points
    Jan 10, 2013 @ 10:05
    Edwin van Koppen
    0

    I've got this and it works:

    @Html.Action("Part", "Menu", Model)

    public class MenuController : SurfaceController
        {
            [ChildActionOnly]
            public ActionResult Part(RenderModel Model)
            {
                IPublishedContent HomeContent = Umbraco.TypedSearch("Home").First<IPublishedContent>();
                MenuViewModel MVM = new MenuViewModel();
                MVM.Children = Umbraco.Content(HomeContent.Id).Children.Where("Visible");
                return PartialView("Menu", MVM);
            }

        }

Please Sign in or register to post replies

Write your reply to:

Draft