Controller, Include in Project
-
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: :)
-
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: :)
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
-
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
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.
-
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.
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
-
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
Thanks for the link and the reply. I will study it :thumbsup:
-
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
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