动态创建MVC应用程序

时间:2016-11-23 09:40:57

标签: c# asp.net-mvc asp.net-mvc-4

我动态生成MVC应用程序。我在这个classlibary中有一个classlibary,我生成一个Controller代码作为String。这个字符串看起来像:

using Microsoft.CSharp.RuntimeBinder;
using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
using System.Text;
using System.Xml;
using System.Xml.XmlConfiguration;
using System.Xml.Serialization;
using System.IO;
using System.Data.SqlClient;
using System.Web.Routing;
using System.Web.Optimization;
using GenerateCode;
namespace Test{

public partial class HomeController : Controller {
    public ActionResult Home(){
        return View();
    }
}

namespace Test{

    public class RouteConfig{
        public static void RegisterRoutes(RouteCollection routes)    
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(name: "Default",url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Home", id = UrlParameter.Optional });    
        }
    }
}
namespace Test{
    public class FilterConfig{
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)    
        {
            filters.Add(new HandleErrorAttribute());            
        }
    }
}
namespace Test{
    public class BundleConfig{
        public static void RegisterBundles(BundleCollection bundles)    
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js")); 
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate*"));
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap.js",
            "~/Scripts/respond.js"));
            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/bootstrap.css",
            "~/Content/site.css"));    
        }
    }
}
namespace Test{
public class MvcApplication : System.Web.HttpApplication   {
        protected void Application_Start()       
        {
           AreaRegistration.RegisterAllAreas();
           FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
           RouteConfig.RegisterRoutes(RouteTable.Routes);
           BundleConfig.RegisterBundles(BundleTable.Bundles); 
        }  
    }
}

我在WPF应用程序中编译此错误。我也生成一个视图。 我的文件夹看起来像

- > bin->用于MVC应用程序的dll和oder dll

- >视图 - >首页> Home.cshtml

- >视图 - > _ViewStart.cshtml

- >视图 - > WebConfig

- > WebConfig

- > Global.asax中

我将此文件夹放入此IIS页面后,我生成了一个新的IIS页面,但我没有显示页面。我认为问题是Global.asax文件,但我该如何解决这个问题呢? 因为Global.asax文件如下所示:

<%@ Application Codebehind="Global.asax.cs" Inherits="Test.MvcApplication" Language="C#" %&GT;

0 个答案:

没有答案