Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Controller, Include in Project

Controller, Include in Project

Scheduled Pinned Locked Moved Web Development
tutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wiep Corbier
    wrote on last edited by
    #1

    Hi, here's a question: I dynamicly create controllers. I put them in the folder Controllers and all is well. For one thing: I can't use them because they are not yet "Include in Project". When I do this manually, it works fine, but that is not the idea. So, how to do this final part also 'dynamic'. What do I need to add to my code :confused: :)

    N 1 Reply Last reply
    0
    • W Wiep Corbier

      Hi, here's a question: I dynamicly create controllers. I put them in the folder Controllers and all is well. For one thing: I can't use them because they are not yet "Include in Project". When I do this manually, it works fine, but that is not the idea. So, how to do this final part also 'dynamic'. What do I need to add to my code :confused: :)

      N Offline
      N Offline
      Nathan Minier
      wrote on last edited by
      #2

      Impossible to answer without knowing how your controller selection is being processed, how you're generating them, and what the technologies involved are.

      "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

      W 1 Reply Last reply
      0
      • N Nathan Minier

        Impossible to answer without knowing how your controller selection is being processed, how you're generating them, and what the technologies involved are.

        "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

        W Offline
        W Offline
        Wiep Corbier
        wrote on last edited by
        #3

        Really? Wll this is how I create a controller

                String\[\] controllerFile = { "using System;",
                                            "using System.Collections.Generic; ",
                                            "using System.IO;",
                                            "using System.Web;",
                                            "using System.Web.Mvc;",
                                            "using Queeste.BusinessLogic;",
                                            "using Queeste.BusinessEntities;",
                                            " ",
                                            "namespace Queeste.GUI.Controllers",
                                            "{",
                                                "   public class " + controllerFileName + " : Controller",
                                                "   {",
                                                "       MenuItemsManager menuItemsManager = new MenuItemsManager(); ",
                                                "",
                                                "       public ActionResult Index()",
                                                "       {",
                                                "           ViewBag.MenuItems = menuItemsManager.GetMenuItems(); ",
                                                " ",
                                                "           return View();",
                                                "       }",
                                                "   }",
                                            "}"};
        
               
                /// Writing the Controller
                string controllerPath = @path\\Controllers\\" + controllerName;
                System.IO.File.WriteAllLines(controllerPath, controllerFile, Encoding.UTF8);
        

        This very morning, I found another solution to solve my problem, so it's not needed to solve this. But, it would be nice to know for future development. Thanks for your reply.

        N 1 Reply Last reply
        0
        • W Wiep Corbier

          Really? Wll this is how I create a controller

                  String\[\] controllerFile = { "using System;",
                                              "using System.Collections.Generic; ",
                                              "using System.IO;",
                                              "using System.Web;",
                                              "using System.Web.Mvc;",
                                              "using Queeste.BusinessLogic;",
                                              "using Queeste.BusinessEntities;",
                                              " ",
                                              "namespace Queeste.GUI.Controllers",
                                              "{",
                                                  "   public class " + controllerFileName + " : Controller",
                                                  "   {",
                                                  "       MenuItemsManager menuItemsManager = new MenuItemsManager(); ",
                                                  "",
                                                  "       public ActionResult Index()",
                                                  "       {",
                                                  "           ViewBag.MenuItems = menuItemsManager.GetMenuItems(); ",
                                                  " ",
                                                  "           return View();",
                                                  "       }",
                                                  "   }",
                                              "}"};
          
                 
                  /// Writing the Controller
                  string controllerPath = @path\\Controllers\\" + controllerName;
                  System.IO.File.WriteAllLines(controllerPath, controllerFile, Encoding.UTF8);
          

          This very morning, I found another solution to solve my problem, so it's not needed to solve this. But, it would be nice to know for future development. Thanks for your reply.

          N Offline
          N Offline
          Nathan Minier
          wrote on last edited by
          #4

          Okay, so it's C# and leveraging the MVC.NET stack, which we didn't know when you asked; so we're already in better shape! I'm glad that you found a solution, but I don't think that I would ever advise this approach unless you're building an application specifically intended to bootstrap simple and tiny CRUD applications, but that doesn't appear to be your intent. From a code/extensibility standpoint, a better approach might be to generate controllers at runtime from your models. I was going to give an approach, but I found a very solid one at: [Generic and dynamically generated controllers in ASP.NET Core MVC | StrathWeb.](https://www.strathweb.com/2018/04/generic-and-dynamically-generated-controllers-in-asp-net-core-mvc/) Have a look at Approach #2, it's a little complex but infinitely extensible and plays nicely with the ecosystem.

          "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

          W Richard DeemingR 2 Replies Last reply
          0
          • N Nathan Minier

            Okay, so it's C# and leveraging the MVC.NET stack, which we didn't know when you asked; so we're already in better shape! I'm glad that you found a solution, but I don't think that I would ever advise this approach unless you're building an application specifically intended to bootstrap simple and tiny CRUD applications, but that doesn't appear to be your intent. From a code/extensibility standpoint, a better approach might be to generate controllers at runtime from your models. I was going to give an approach, but I found a very solid one at: [Generic and dynamically generated controllers in ASP.NET Core MVC | StrathWeb.](https://www.strathweb.com/2018/04/generic-and-dynamically-generated-controllers-in-asp-net-core-mvc/) Have a look at Approach #2, it's a little complex but infinitely extensible and plays nicely with the ecosystem.

            "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

            W Offline
            W Offline
            Wiep Corbier
            wrote on last edited by
            #5

            Thanks for the link and the reply. I will study it :thumbsup:

            1 Reply Last reply
            0
            • N Nathan Minier

              Okay, so it's C# and leveraging the MVC.NET stack, which we didn't know when you asked; so we're already in better shape! I'm glad that you found a solution, but I don't think that I would ever advise this approach unless you're building an application specifically intended to bootstrap simple and tiny CRUD applications, but that doesn't appear to be your intent. From a code/extensibility standpoint, a better approach might be to generate controllers at runtime from your models. I was going to give an approach, but I found a very solid one at: [Generic and dynamically generated controllers in ASP.NET Core MVC | StrathWeb.](https://www.strathweb.com/2018/04/generic-and-dynamically-generated-controllers-in-asp-net-core-mvc/) Have a look at Approach #2, it's a little complex but infinitely extensible and plays nicely with the ecosystem.

              "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Nice link. I might have a use for that one soon. :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups