Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 02:01
    Ayo Adesina
    0

    Using Surface Controllers with Umbraco 7

    I am trying to post a form to a surface controller from a partial view contact form.

    When I installed Umbraco 7 there was no 'Controllers Folder' in the solution so I created a folder called Controllers and I have added a ContactController.cs

     public class ContactController : SurfaceController
     { 
        [HttpPost]
        public ActionResult SendMail(Contact form)
        {
            //code here
        }       
     }
    

    then inside my partial view I have:

    using (Html.BeginUmbracoForm("SendMail", "Contact",null, new { @class =""}))
    {
    @Html.ValidationMessageFor(model => model.YourName)
        @Html.ValidationMessageFor(model => model.Email)
     @Html.ValidationMessageFor(model => model.Subject)
      @Html.ValidationMessageFor(model => model.Message)  
    
    @Html.ValidationSummary(true,"Errors")
    
        @Html.EditorFor(model => model.YourName)
    
    
        @Html.EditorFor(model => model.Email)
    
    
        @Html.EditorFor(model => model.Subject)
    
    
        @Html.TextAreaFor(model => model.Message) 
    
    
        <input type="submit" id="submit-mail" class="submit-btn rounded" value="SEND MESSAGE" />
    

    Page loads fine... when I hit the submit button I get: Could not find a Surface controller route in the RouteTable for controller name Contact

    I am using V7 do I need to put anything in my Global.ascx file... ?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 26, 2014 @ 07:19
    Jan Skovgaard
    0

    Hi Ayo

    I'm not sure why the error happens but I'm wondering if you have had a look at the documenation about forms here http://our.umbraco.org/documentation/master/Reference/Templating/Mvc/forms - Perhaps there is something useful in there about how to do this.

    Hope this helps, /Jan

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 10:24
    Ayo Adesina
    0

    the fact that i had to add a controllers folder? is that right? or is there some pre determined place i should add these

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 10:31
    Jeavon Leopold
    104

    Hi Ayo,

    Do you have a visual studio solution? If you do, then this is fine, you can build your solution, if not, then you will need to move your controller file to the app_code folder for it to work.

    Jeavon

  • Halima Koundi 8 posts 79 karma points
    Feb 12, 2016 @ 16:50
    Halima Koundi
    0

    Hi Jeavon,

    Thank you for this answer, it was indeed my issue. I did not want to go through the hassle of creating a visual studio application , but just needed to add some WebApi controller.

    But I was not putting them on the right folder ..

    Thanks a lot !

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 10:53
    Ayo Adesina
    0

    Yes I have a VS solution... just went through the documentation that you posted... looks like I am doing everything as it should be...

    really not sure where to go from here...

    One thing that I have noticed though is in the new Umbraco 7 is there is a Global.asax file by default, and inside that file we have

    <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
    

    but where is the Global.asax.cs file?

    With slightly older versions of umbraco when they are installed they have both a Global.asax file and Global.asax.cs file could this be part of the problem..?

    Can I add a Global.asax.cs file?

    What is the difference between the way that file is used in 6 and the way it is used in 7?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 11:06
    Jeavon Leopold
    0

    Ok, then you should just build your solution, that should create a dll file in the bin folder from your controller. You should check your .cs file is set to compile.

    if that still doesn't work try deleting the /app_data/temp/plugins folder and then restart the app pool.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 11:42
    Jeavon Leopold
    0

    I think also your controller needs to be suffixed with SurfaceController

    E.g.

    public class ContactSurfaceController : SurfaceController
    

    And

    using (Html.BeginUmbracoForm("SendMail", "ContactSurface",null, new { @class =""}))
    
  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 11:51
    Ayo Adesina
    0

    Yeah I read that some where before and gave it a go no joy.... but I think that was with earlier versions now you just need to inherit from the umbraco SurfaceController.

    This is my solution - created by web matrix

    enter image description here

    I tried to delete every thing in the bin folder and rebuild but it will not build at all when I delete all the bin files so I had to undelete it, how can I check that ContactController is set to be complied I remember you could set this in the properties window when you select the file but there is no option for that just the file name and the path.

    enter image description here

    And this is the content of my Bin folder
    Any more ideas?

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 12:02
    Ayo Adesina
    0

    I just opened up one of my older projects where I have surface controllers and when I click on the files in that list I do have all the options I was looking for ie build action: compile... etc

    What I have noticed is this project is a website (created using web matrix) where this project is a visual studio project so I guess that's why I don't have the options like compile on the .cs file in this project and have it in my old project.

    So what do I try next.. I wonder...............hmmmmmmmmmmmmmmmmmm :-S

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 12:31
    Jeavon Leopold
    0

    Yes, I was just writing that! You will need to create a web application project as web sites don't compile.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 12:32
    Jeavon Leopold
    0

    Once created you can then include the files you need.

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 12:34
    Ayo Adesina
    0

    Fixed it!

    Jeavon Leopold You where right... when you said..

    "move your controller file to the app_code folder for it to work."

    Even though I have a visual studio solution, I set up the website using web-matrix and it created a 'WebSite' and though from Web-Matrix I can click visual studio and see all the files in VS it obviously works in a different way and code that needs to be complied still needs to go in app_code folder.

    I would love it if some one could explain the different work flows when using web-matrix and when using a solution, this is something that confuses me a lot in umbraco.

    So I solved my problem by putting my controller file inside the App_code folder. Hope this helps someone else.

    If someone could explain how this all works so I understand what is going on under the hood, I would be much appreciative

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 12:49
    Ayo Adesina
    0

    'Web Sites Don't compile' < Some times someone just needs to point out the obvious :-) Makes totally sense now what I would need to compile the whole thing is a web-application, generally I ALL WAYS work with applications so I overlooked the fact that it was a website.

    So question............. should I convert my website in to a web application or do I just put everything that needs to be complied in to the app_code folder.

    What is the advantages? and disadvantages... of this...?

    and

    WHY THE HELL....don't you have an option to set it up as a website or as a web-application when using web-matrix.

    I love umbraco, but its shit like this that makes me hate it. I have used the surface controller thing a few times, but how would I know to put it in the app_code folder... none of the tutorials I have seen point this out!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 26, 2014 @ 13:16
    Jeavon Leopold
    0

    Hi Ayo,

    Great it's working for you now!

    Of course this isn't directly a Umbraco thing, it's a Visual Studio project type confusion.

    Generally if you are using VS then you should use a web application, this means your code is compiled into assembly which is all you need to deploy and is efficient as it's already compiled.

    However there is always a app_code folder where you can place code which compiled at application startup, of course this lengthens startup time, but it can be useful sometimes.

    I hope that makes some sense of it.

    Jeavon

  • Ayo Adesina 430 posts 1023 karma points
    May 26, 2014 @ 16:48
    Ayo Adesina
    0

    Yes it does thanks... :-)

    Ok so I always want to use VS really. So whats the best way to get Umbraco installed, using Nuget? if so what project type should I start with?

    Or is it better to download umbraco and install it manually? I have used web-matrix because it is easy to install a base project...

    What do you think is the best way.... not the over the top way, but I want to use VS and I don't really want to have a copy tool that copies from one dir to another every time I want to run the site :-) been there before...

    So....

    What is the best way.........

    Should I convert my current webmatrix project or should I start again I only have one page and a surface controller I can recreate?

  • Pedro Almeida 2 posts 71 karma points
    Feb 24, 2016 @ 16:15
    Pedro Almeida
    0

    I have installed Umbraco in a web site project. And I had the same problem.

    After copy controllers (UmbracoApiController and SurfaceController) to App_Code folder, it starts working correctly but, the SurfaceController is still throwing an error.

    Anyone can help me ?

    (My Umbraco version is 7.4.0)

    Folder structure:

    enter image description here

    Error:

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.

    enter image description here

  • Pedro Almeida 2 posts 71 karma points
    Feb 24, 2016 @ 16:34
    Pedro Almeida
    0

    I found the solution on : http://stackoverflow.com/questions/21096156/why-am-i-getting-the-yellow-screen-of-death-on-an-umbraco-surfacecontroller-on-a

    The Surface controllers need to be inside "Controllers" namespace :

    enter image description here

  • pat 124 posts 346 karma points
    Feb 03, 2017 @ 10:32
    pat
    0

    Hi all, interesting discussion old post but I am confused why dont you copy dll file instead of controller code

    I am trying to create login / sign up and lot more controllers. what I have done is I have created my partial view , controller and Model in my visual studio project 1. copy over the partial view to ~/Views/Partials/ folder 2. copy over .dll file from my visual studio project to web site bin folder 3. created a macro in CMS to call render view then insert Macro using RTE on my page

    I get this Route table error ... my Controller inherits from sufacecontroller

    so what do i do wrong here ? here is my recent post about it https://our.umbraco.org/forum/templates-partial-views-and-macros/83703-could-not-find-a-surface-controller-route-in-the-routetable-for-controller-name-error

Please Sign in or register to post replies

Write your reply to:

Draft