Copied to clipboard

Flag this post as spam?

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


  • Mario 10 posts 80 karma points
    Feb 28, 2019 @ 10:04
    Mario
    0

    Can't add a controller?

    New at Umbraco, I've been following the Umbraco TV tutorials and I was trying to create a login-controller, but in my project this is what happens:

    Controller And the "Web User Control" creates an .aspx with: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginController.ascx.cs" Inherits="Controllers_LoginController" %>

    What should I do?

  • Marius 6 posts 77 karma points
    Feb 28, 2019 @ 15:44
    Marius
    0

    By the looks of it you are trying to add a controller while running the solution in debugging mode. Click this button enter image description here

    and try to add controller again.

  • Carlos Mosqueda 244 posts 435 karma points
    Feb 28, 2019 @ 16:11
    Carlos Mosqueda
    0

    @Mario, if that is the case, than yes Marius is correct.

    Was this your issue?

  • Matt Birch 6 posts 96 karma points
    Feb 28, 2019 @ 16:15
    Matt Birch
    0

    You definitely don't want to see Web User Control in the right-click menu (that's what causing the ascx and ascx.cs files).

    Is this project set up as a Web Application in VS? If not, delete and make sure it is (and set up an empty ASP.NET project when you get the prompts. Then install Umbraco via Nuget).

    Hope that helps!

  • Mario 10 posts 80 karma points
    Feb 28, 2019 @ 16:19
    Mario
    0

    When the project was stopped the problem persisted.

    And though completely deleting the project and starting fresh from a nuget package (Not version 8 though because it gives me errors) does allow me to add controllers.

    My concern is that the project that didn't allow me to add a Controller was the one I'd downloaded from the cloud/server using GitKraken.

    Is there a potential solution that doesn't involve having to start from scratch?

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Feb 28, 2019 @ 17:19
    Nik
    0

    Hi Mario,

    sounds like it's an Umbraco Cloud project.

    Can you confirm if this is Umbraco V8 or Umbraco V7 you are running?

    Something to note, just because you are missing an option from the context menu doesn't mean you can't create the right sort of file. It might just mean you don't get some of the boilerplate code.

    A controller is "just" a class file, but there if you don't have the option to add a class you can "cheat" the program a bit. If you select "JavaScript File" and then call it "MyController.cs" it will create a cs file.

    In this file, delete everything it autopopulates it with (if it does) and there you have a blank C# class file ready to go :-)

    For example you could add the following code (note, you'd need to add the correct namespaces)

    public class MyController : SurfaceController
    {
    
    }
    

    This would give you a controller called "MyController" :-)

    Might help,

    Thanks

    Nik

  • Carlos Mosqueda 244 posts 435 karma points
    Feb 28, 2019 @ 17:14
    Carlos Mosqueda
    0

    @Mario,

    Typically we use PM in Visual Studio. Might be a start over, however, it is pretty easy to copy and paste work already done.

    Your best bet is to do the following. Works every time. We don't use the Git pull, we usually use the Nuget Package manager.

    Install .Net 4.7.2 if you have not done so

    1. Open Visual Studio
    2. Create new project
    3. Choose a Web project and an ASP.NET Web Application(.NET Framework), of course using 4.7.2
    4. Choose and 'Empty' application from the Project Templates dialog that pops up in Visual Studio and leave all the "Core references" unselected.
      All the MVC stuff will come in with the PM pull. Click 'OK'
    5. In the Visual Studio hover over 'Tools' from the toolbar, hover over Nuget Package Manager > choose Package Manager Console
    6. In the Package Manager Console, enter after the PM >

    Install-Package UmbracoCms -Version 8.0.0

    1. This will pull everything from the Package Manager from NuGet. It will install all MVC Dlls, framework stuff, and all of Umbraco.

    After that, you will run your project and continue onward. If there is not a Controllers folder, you will just have to add a new Folder to the project called "Controllers" and then within that folder you would be able to create a new controller file.

    Let me know if you have any questions.

Please Sign in or register to post replies

Write your reply to:

Draft