【问题标题】:i have a helper that use Activator.CreateInstance("Sitaad.Models","table") but not found assembly我有一个使用 Activator.CreateInstance("Sitaad​​.Models","table") 但没有找到程序集的助手
【发布时间】:2016-07-26 18:03:59
【问题描述】:

我的 app_code 文件夹中有一个 Helper 函数

public static MvcHtmlString DisplayNameFor(string table, string FieldName)
    {
        string Name = "";
        //Type tt = new FilesList().GetType();
        //var Property = tt.GetProperty(FieldName);        
        Type tt = Type.GetType(table, true);        

        var Property = Activator.CreateInstance(tt.FullName,"FilesList").GetType().GetProperty(FieldName);
        var attr = Attribute.GetCustomAttribute(Property, typeof(TurboDisplayAttribute));

        if (attr.GetType() == typeof(TurboDisplayAttribute))
        {
            Name = ((TurboDisplayAttribute)attr).Name;
        }
        G gg = new G();
        gg.SetDbContext(new ApplicationDbContext());
        Name = gg.T(Name);

        return new MvcHtmlString(Name);
    }

但是当我在我的视图中使用这个助手时:

@Helpers.DisplayNameFor("Sitaad.Models", "Order")

它显示错误:无法从程序集“App_Code.xiomuct6, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”中加载类型“Sitaad​​.Models”。

我该怎么办?

【问题讨论】:

    标签: c# asp.net-mvc entity-framework model


    【解决方案1】:

    尝试从配置设置中删除App_Code。在Web.Config 中,它应该看起来像这样:

    <httpModules>
       <add name="LanguageSettingModule" type="LanguageModule" />
    </httpModules>
    

    【讨论】:

    • 那个项目现在关闭了,你确定这个工作吗?如果是,我将其作为正确答案。
    • 我能告诉你什么?如果你不尝试你不会知道,但它对我有用,所以......
    猜你喜欢
    • 2017-01-13
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 2014-09-26
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    相关资源
    最近更新 更多