0

I created Dynamic Controller in MVC and that file having in Controller Folder but created controller not reflecting in Solution-Explorer Controller Folder by manually add that dynamic controller work fine, so here my problem how to reflect the Controller Class in Controller folder

        StringBuilder sb = new StringBuilder();            
        sb.Append("using System;" + Environment.NewLine);
        sb.Append("using System.Collections.Generic;" + Environment.NewLine);
        sb.Append("using System.Data;" + Environment.NewLine);
        sb.Append("using System.Data.SqlClient;" + Environment.NewLine);
        sb.Append("using System.Dynamic;" + Environment.NewLine);
        sb.Append("using System.Linq;" + Environment.NewLine);
        sb.Append("using System.Text;" + Environment.NewLine);
        sb.Append("using System.Web.Mvc;" + Environment.NewLine);

        sb.Append("namespace Testing_MVC.Controllers" + Environment.NewLine);
        sb.Append("{" + Environment.NewLine);

        sb.Append("public class " + ctrl + "Controller" + " : Controller" + Environment.NewLine);
        sb.Append("{" + Environment.NewLine);

        sb.Append("public ActionResult Index()" + Environment.NewLine);
        sb.Append("{" + Environment.NewLine);
        sb.Append("return View();" + Environment.NewLine);
        sb.Append("}" + Environment.NewLine);

        sb.Append("}" + Environment.NewLine);

        sb.Append("}" + Environment.NewLine);

        var dir = Server.MapPath("~\\Controllers");
        var file = System.IO.Path.Combine(dir, ctrl + "Controller" + ".cs");
        System.IO.Directory.CreateDirectory(dir);
        System.IO.File.WriteAllText(file, sb.ToString());

        return this.RedirectToAction("Index", ctrl, new { id = 1 });

by calling html working fine as MVC Routing:

window.location.href = '@Url.Action("common_dll", "Home")?ctrl=Test';

need automatically reflect that class in Controller folder by C# programme without manually.

ethiraj
  • 67
  • 11

1 Answers1

0
I mention that the anwser does not belong to me. In the past I had issues with the MVC. 
Here is the complete question history.
https://stackoverflow.com/questions/9988634/ajax-call-into-mvc-controller-url-issue

 In order for this to work that Javascript must be placed within a Razor view so that the line

        @Url.Action("Action","Controller")

        is parsed by Razor and the real value replaced.

        If you don't want to move your Javascript into your View you could look at creating a settings object in the view and then referencing that from your Javascript file.

        e.g.

        var MyAppUrlSettings = {
            MyUsefulUrl : '@Url.Action("Action","Controller")'
        }

        and in your .js file

        $.ajax({
         type: "POST",
         url: MyAppUrlSettings.MyUsefulUrl,
         data: "{queryString:'" + searchVal + "'}",
         contentType: "application/json; charset=utf-8",
         dataType: "html",
         success: function (data) {
         alert("here" + data.d.toString());
        });

        or alternatively look at levering the framework's built in Ajax methods within the HtmlHelpers which allow you to achieve the same without "polluting" your Views with JS code.

        Dont forget the slash before 'Controller'. It will create an incorrect URL. byut yes, this is what I use now. 
Surfer
  • 23
  • 7
  • no no i need physical file have to reflect in Solution Controller folder, if worked means no need to create many controller, whenever need controller can create and remove so simple – ethiraj May 17 '19 at 07:10
  • i created automatic Controller but that created file having in Physical folder but not reflect in Application Controller folder once reflect means it will work fine that is only problem – ethiraj May 17 '19 at 07:12