3

I have a C# class, and inside this class I have a string variable (global) whose value is needed in a cshtml file. What can I do to retrieve it? Thanks very much in advance!

1
  • What's a global variable in C#? Commented Aug 8, 2012 at 2:30

2 Answers 2

2

If you have something like this:

namespace Site.Controllers 
{
    public class Globals
    {
        public static String title = "foobar";
    }
}

Then you can access it in cshtml files like this:

<div>@Site.Controllers.Globals.title</div>
Sign up to request clarification or add additional context in comments.

Comments

0

If it is an instance variable, you can pass it down as part of the model. If it is a static variable, then you can explicitly access it the same way you would use any other variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.