Copied to clipboard

Flag this post as spam?

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


  • Damien (Slipoch) 62 posts 346 karma points
    Jul 22, 2016 @ 05:02
    Damien (Slipoch)
    0

    Umbraco Noob here, I have found the documentation to be very underdeveloped for Umbraco 7 as it seems to rely on people having used prior versions.

    I have created a surface controller and uploaded it to the site.

    I have tried creating it VS2015 and it does not work, the documentation is incredibly light on any details as to how it should be implemented exactly. (should it use namespaces etc.)

    Yes put the cs file in the controllers folder and make sure there is a corresponding action cshtml file in a folder named the same as the controller.

    Folder Structure

    Controller:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
        public class ClassifiedController : Umbraco.Web.Mvc.SurfaceController
        {
            // GET: Classified
            [HttpPost]
            public ActionResult index()
            {
    
                return View();
            }
        }
    

    index.cshtml

    @{
         Layout = null;
    }
    
    
    <div>
        <div> 
            hello
        </div>
    </div>
    

    Error message below, I believe it is happening when it tries to find routes or something to that effect. Error Message

    Stacktrace: enter image description here

    Are there any actual tutorials out there to create and apply surface controllers? Anybody know what is going on?

    If you have a solution, please do not assume I know what libraries you are using and paste all your code.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jul 22, 2016 @ 06:30
    Dennis Adolfi
    0

    Hi Damien.

    First problem is you should´nt use [HttpPost] above your ActionResult. Either remove that or use [HttpGet]. This is not Umbraco specific but more a MVC standard: http://www.tutorialsteacher.com/mvc/actionverbs-in-mvc

    Second problem is Im not sure what Url you are requesting?

    All locally declared controllers get routed to:

    /umbraco/surface/{controllername}/{action}/{id}

    So in your scenario, you URL will be /Umbraco/Surface/Classified/Index

    Also what documentation have you been reading? This one? https://our.umbraco.org/documentation/reference/routing/surface-controllers.

    Based on your images im not sure if it´s actually a SurfaceController that you want to use, since SurfaceControllers are used for MVC Child Actions and for handling form data submissions and not for rendering complete pages. I think whatr you want is a Custom Controller (also called RenderMvcController and Hijacking Umbraco Routes). https://our.umbraco.org/documentation/reference/routing/custom-controllers.

    Also if you are new to Umbraco and find it difficult, i recommend you to get a subscrition to http://www.umbraco.tv/ for great video tutorials and maybe look up a Umbraco Traning center https://umbraco.com/products/training.

    Best of luck to you!!

  • Damien (Slipoch) 62 posts 346 karma points
    Jul 22, 2016 @ 07:01
    Damien (Slipoch)
    0

    Sorry Dennis, I didn't mean to leave the httppost in, it is indeed for taking in form data so it will eventually be required to be a post call and will attempt to redirect to a particular page.

    /Umbraco/Surface/Classified/index does not exist after uploading the file to the controllers, however /Classified does.

    The documentation you link to is exactly what I was reading, it is very light and skips info about what usings are present, whether namespaces are used etc.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jul 22, 2016 @ 07:38
    Dennis Adolfi
    0

    Have you build the solution?

    Try to upload the /Controllers/ClassifiedController.cs + Views/Classified/Index.cshtml + and your solution .bin file to the server and see how that works.

    Also do you have it working locally?

  • Damien (Slipoch) 62 posts 346 karma points
    Jul 29, 2016 @ 02:54
    Damien (Slipoch)
    0

    Not working locally as VS does not recognise the Umbraco.Web.Mvc (only Umbraco.Web.UI available)

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jul 22, 2016 @ 07:40
    Dennis Adolfi
    0

    Also, here is my code, so you can see namespaces used:

    /Controllers/ClassifiedController.cs

    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
    namespace MyUmbracoSite.Controllers
    {
        public class ClassifiedController : SurfaceController
        {
            // GET: Classified
            public ActionResult Index()
            {
                return View();
            }
        }
    }
    

    So in the above example, you need to upload the /Bin/MyUmbracoSite.bin file to the server.

  • Damien (Slipoch) 62 posts 346 karma points
    Jul 29, 2016 @ 02:53
    Damien (Slipoch)
    0
    using Umbraco.Web.Mvc;
    

    This does not exist according to VS2015

    Is there any way of creating surface files or making a form to post back to Umbraco without using js or a surface controller?

    Or even making the surface controller from within the Umbraco interface as it tries to make you do for everything else.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jul 29, 2016 @ 06:15
    Dennis Adolfi
    0

    Hi Damien.

    Looking at your picture of your file-structure. Have you installed Umbraco in this solution? I cant see any Umbraco specific folder in your file structure like the Config folder, media, Umbraco or Umbraco_Client. Or maybe they are just hidden?

    If you have Umbraco successfully installed i have no idea why your solution cant find Umbraco.Web.Mvc, sorry.

  • Damien (Slipoch) 62 posts 346 karma points
    Aug 05, 2016 @ 01:12
    Damien (Slipoch)
    100

    Ok, so this was a project created from Azure using teamviewer, it turns out it does not work correctly as it does not 'pull' down half the required information needed for compilation in Visual studio.

    So it would be ok as long as you don't need surface controllers

    Solution was to create a new EMPTY asp project, do NOT allow MVC to install as it creates conflicts with a version of MVC installed with the nuget package of Umbraco.

    Of course that meant I had to package up my old site and load it onto the new instance, which caused it's own mixed bag of issues.

    A couple of followup questions: I assume I have to create the folder controllers for surface controllers?

    When you refer to MyUmbracoSite.bin this would be the MyUmbracoSite.dll.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Aug 05, 2016 @ 06:21
    Dennis Adolfi
    0

    Ah ok i understand.

    Yeah it did´nt sound like you had all the files you needed.

    Glad it worked out for you eventually!

    Follow up question 1: Actually you can place your SurfaceController anywhere you want in you project and Umbraco will still pick this Controller up. But yeah it looks a lot cleaner to have a dedicated folder called "Controllers" in your project, so it looks and feels like a regular MVC application.

    Follow up question 2: Yes, hehe, thats a typo. It should be MyUmbracoSite.dll.

  • Damien (Slipoch) 62 posts 346 karma points
    Aug 05, 2016 @ 06:22
    Damien (Slipoch)
    1

    Cheers man, thanks for all the info.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Aug 05, 2016 @ 06:23
    Dennis Adolfi
    0

    No problem! Have a great day! :)

Please Sign in or register to post replies

Write your reply to:

Draft