Copied to clipboard

Flag this post as spam?

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


  • Fernanda Bernardes 27 posts 147 karma points
    May 09, 2016 @ 14:13
    Fernanda Bernardes
    0

    Controllers Different between Umbraco 7 and Umbraco 7.4.3

    Hi, Folks!!

    I'm trying to create a form using MVC (I'm following some tutorials on the same matter) and when I link the action created in the controller within the view that the Umbraco will manage, I use the policy:

    @using My_Umbraco.Controllers
    

    (Where My_Umbraco is the name of my project)

    It generated an error indicating that it can not understand this project name ... What I am unable to understand is that the tutorials I'm following always refer to version 7 and this project name usage works perfectly. Since I am using the 7.4.3 version, it shows some screen differences between the version 7 of the tutorials I'm questioning myself if this way of indicating the drivers created by us is modified.

    Does anyone know tell me if I am correct? Is it necessary to inform the Umbraco where my controllers? Is there any configuration that is required to be made to the Umbraco 7.4.3 understand the name of my project during the execution? Below show the screens programmed with the result that the Umbraco returns me ... enter image description here enter image description here enter image description here enter image description here Please, I'm already several days trying to solve this issue and I am not finding the solution Not one forum, blog or Umbraco documentation.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 09, 2016 @ 14:27
    Steve Morgan
    0

    Hi,

    Have you included the controller file into the Visual Studio project? Check in the solution explorer - if it's a grey outline then right click and "Include in project".

    Steve

  • Fernanda Bernardes 27 posts 147 karma points
    May 09, 2016 @ 14:30
    Fernanda Bernardes
    0

    Complementing the information:

    In these tutorials I'm following, when the tutorial executor creates a new template, the Umbraco puts the following information:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = "Master.cshtml";
    }
    

    In Umbraco 7.4.3, when we create a new template, the information entered by him change:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.ContactForm>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    

    It may be that the issue that takes Umbraco to reject the @using command with the name of my project?

  • Fernanda Bernardes 27 posts 147 karma points
    May 09, 2016 @ 14:51
    Fernanda Bernardes
    0

    HI, Steve!!

    Thanks for your answer. I done the Controller by VS, but I checked and the controllers is include in my project.

    enter image description here

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 09, 2016 @ 15:20
    Steve Morgan
    0

    Hi,

    Is the build action set to Compile?

    (Look in the Properties).

    Steve

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 09, 2016 @ 15:21
    Steve Morgan
    0

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 09, 2016 @ 15:52
    Steve Morgan
    0

    HI,

    Just comparing what you have to a working example here.

    There is no need to add a @using for the My_Umbraco.Controllers - take that line out of your view.

    Steve

  • Fernanda Bernardes 27 posts 147 karma points
    May 09, 2016 @ 19:52
    Fernanda Bernardes
    0

    Steve,

    I done your suggest, but now show me other error.... I am crasy !!! enter image description here

    I change to

    @Html.Action("ShowForm","ContactSurfaceController")
    

    But the same error show me.

    Do you have other idea to me? (I'm entering the zone of despair :#)

    Thank you for your patience with me

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 10, 2016 @ 09:25
    Steve Morgan
    100

    Hi,

    I've just been through and created the same setup you have and it worked perfectly :( Sorry to add to the despair!

    Sorry to ask but - you are building the solution each time, right? The Controllers and models are built into dlls - when using Umbraco it can be confusing what's needs to be built and compiled and what can be changed at runtime (e.g. Views). The error you're showing is Umbraco saying it can't find the Controller (or the method on it). Usually this is a typo - though I'm convinced what you have is right.

    If you are building try a clean and rebuild and a restart of VS - never underestimate the bugginess of VS! Stick a break point on the ShowForm method to see if it is hitting it (though I'm sure it isn't).

    Failing that the only piece of the puzzle you haven't posted is the Contact Form partial view. Can you confirm that under /Views/Partials/ you have ContactForm.cshtml (I'd expect a different error though here - I just don't think we're hitting the Controller)?

    To rule out some VS funniness try a fresh example - I've written a tutorial which is MVC but for member login but the code download should just "work" - perhaps try it with a fresh copy of Umbraco?!

    http://siempresolutions.co.uk/blog/UmbracoMembersPart3AFullSolution

    Steve

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 10, 2016 @ 14:30
    Steve Morgan
    0

    Grr that link should be:

    Umbraco Members Full Solution Blog post

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    May 10, 2016 @ 09:53
    Nik
    0

    I've seen some oddities when creating surface controllers in the past, with no real explanation as to why.

    Try changing your controller declaration to:

    //Remove the surface from the name of the class
    public class ContactController : SurfaceController
    

    Then try calling your action with the following:

    @Html.Action("ShowForm","Contact")
    
  • Fernanda Bernardes 27 posts 147 karma points
    May 10, 2016 @ 14:04
    Fernanda Bernardes
    0

    Steve, than you so much for your help... You are right. After rebuild the solution, Umbraco found the controller.

    Nik, after work as the solution given by Steve, I tested both forms of creation of Controller: your way to create and how I had created. Both ways worked. Thank you very much for your answer.

    Thanks a both.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    May 10, 2016 @ 14:30
    Steve Morgan
    0

    No worries!

    Happy to help! I found once you've got your first working MVC controller it's much easier in the future to compare and find out what's not working!

  • Martin Lloyd Jose 2 posts 72 karma points
    Jun 26, 2017 @ 10:34
    Martin Lloyd Jose
    0

    I do have the same problem, but in my case, there is no existing namespace declaration. I am still having this problem until now.

    As what I have observed on some developers, whenever they create a new class, a namespace declaration would automatically be generated same as the name of the project.

    The problem that I am now facing is that I don't know the namespace associated in this project. And even if I am going to create a namespace declaration and rebuild the project, it still won't work.

    I hope you can help me with this. Thanks. enter image description here

  • Fernanda Bernardes 27 posts 147 karma points
    Sep 28, 2017 @ 14:25
    Fernanda Bernardes
    0

    Martin, I hope you is all right!!

    I donĀ“t know if you find the solution to your problem, but look the picture, I read that you done a Controller, but not extends a SurfaceController. Look the line:

    public class ContactSurfaceController

    change to:

    public class ContactSurfaceController: SurfaceController

Please Sign in or register to post replies

Write your reply to:

Draft