Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:35:12+00:00 2026-06-04T08:35:12+00:00

I have a C# model that gets populated through its constructor. I would like

  • 0

I have a C# model that gets populated through its constructor. I would like to place this object in my _Layout.cshtml so my Javascript can use it as settings.

Here is what my model looks like:

public class SomeConfig
{
    public string PropertyA { get; set; }
    public string PropertyB { get; set; }
    public string PropertyC { get; set; }

    public SomeConfig()
    {
        PropertyA = SystemSettings.getSetting(KEYA);
        PropertyB = SystemSettings.getSetting(KEYB);
        PropertyC = SystemSettings.getSetting(KEYC);
    }
}

I would like to initialize and output this in _Layout.cshtml so all my other views can use it. So far I am only able to figure out how to do this manually in _Layout.cshtml like this:

<script type="text/javascript">
    MyNamespace.someConfig = {
        PropertyA: @SystemSettings.getSetting(KEYA),
        PropertyB: @SystemSettings.getSetting(KEYB),
        PropertyC: @SystemSettings.getSetting(KEYC)
    }
</script>

This is horrible because every time the SomeConfig.cs model gets extended, I have to remember to extend it manually client-side. Is there a way to initialize it in the _Layout.cshtml so it creates a Javascript object dynamically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:35:13+00:00Added an answer on June 4, 2026 at 8:35 am

    Try instead to do

    <script type="text/javascript">
        MyNamespace.someConfig =  @Json.Encode(SystemSettings);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that gets it's view-count updated after it's viewed. This is
I have a model that looks like this: Performance - Location - Event -
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
How can i have model in knockoutjs that gets its data from an sqlite
I have a GalleryPhoto model with a paperclip attachment that gets processed into a
I have a Model that named word. this is my word model public class
I have a model that looks like: [Serializable] public class TemplatePageModel { public PageModel
In my application, I have a model object that contains a collection lets say
I have a model called Vote that gets changed very frequently (people voting on
I have 2 pages. The first page has a dialog that gets populated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.