Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an internal class in razor view

I have an internal class present in the Web.Properties as a setting class Settings.settings.Now I want to use its properties of Settings class in the razor view (.cshtml file)of in mvc 4

The following code is of the setting file (auto generated)

[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class UIMessagesSettings : global::System.Configuration.ApplicationSettingsBase {

    private static UIMessagesSettings defaultInstance = ((UIMessagesSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new UIMessagesSettings())));

    public static UIMessagesSettings Default {
        get {
            return defaultInstance;
        }
    }

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("An error occured while loading grid data.")]
    public string GridErrorMsg {
        get {
            return ((string)(this["GridErrorMsg"]));
        }
    }
  }
}

I want to use the GridErrorMsg property in the razor view (.cshtml) I have tried using the following code

@Properties.UIMessagesSettings.Default.GetType()

but it says UIMessagesSettings can't be accessed as it is an internal class.Any solutions to this problem?

like image 265
neel shah Avatar asked Aug 27 '14 06:08

neel shah


1 Answers

You should either make your class public or compile your views in same assembly

Also you can use "internal friendly" http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx if your views are compiled in separate assembly

If you do not compile views in single library you can not use internal class there because runtime compiles them to separate assembly and thi assembly will not see internal classes from others

If you really need it, you shall change the generator if possible

like image 68
Vladmir Avatar answered Oct 04 '22 23:10

Vladmir