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

  • Home
  • SEARCH
  • 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 395075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:25:05+00:00 2026-05-12T16:25:05+00:00

In ASP.NET WebForms you can reference appSettings directly in your markup with this syntax:

  • 0

In ASP.NET WebForms you can reference appSettings directly in your markup with this syntax:

<%$ MySettingKey %>

Unfortunately this does not work in ASP.NET MVC because, as MSDN points out, this syntax only works in server controls.

I’ve run into a few situations where I would love to use this syntactic sugar in an ASP.NET MVC view (WebFormsViewEngine). Does anyone know if there is a way to get this working?

Seems like we might be able to derive from WebFormsViewEngine and add this as a feature, perhaps?

  • 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-05-12T16:25:05+00:00Added an answer on May 12, 2026 at 4:25 pm

    Not very clean but in an ASP.NET MVC View you could actually write this:

    <asp:Literal ID="dummy" runat="server" Text="<%$appSettings:MySettingKey%>" />
    

    Which will effectively print whatever the value you have in appSettings:

    <appSettings>
        <add key="MySettingKey" value="SOME VALUE"/>
    </appSettings>
    

    Oh and there won’t be a VIEWSTATE tag added to your page 🙂

    Now to the point: I will strongly discourage you doing something like this MVC. It is not the View’s responsibility to pull the data to show, it’s the controller that needs to pass it. So I would make MySetting a property of the ViewModel which will be populated by the controller and passed to the view to be shown.

    public ActionResult Index()
    {
        var model = new SomeViewModel
        {
            // TODO: Might consider some repository here
            MySetting = ConfigurationManager.AppSettings["MySetting"]
        }
        return View(model);
    }
    

    And in the View:

    <%= Html.Encode(Model.MySetting) %>
    

    or even shorter with the new syntax introduced in ASP.NET 4:

    <%: Model.MySetting %>
    

    UPDATE:

    Yet another alternative if you think that MySetting is not a property of the ViewModel (like some css name or similar) you could extend the HtmlHelper:

    public static string ConfigValue(this HtmlHelper htmlHelper, string key)
    {
        return ConfigurationManager.AppSettings[key];
    }
    

    And use it like this:

    <%= Html.Encode(Html.ConfigValue("MySetting")) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 194k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This will work: sudo sh -c "echo 'deb http://ppa.launchpad.net/person/ppa/ubuntu karmic… May 12, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer Okay, I found the answer (http://osdir.com/ml/jquery-ui/2009-04/msg00769.html) -- the contents of… May 12, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer If you want to return a single string containing all… May 12, 2026 at 6:45 pm

Related Questions

There's a lot to C# & ASP.net. Where should I start? What should I
Here's the background info first. ASP.NET 2.0 Web Site with AJAX Extensions 1.0. I
So, my question is, can any of the ASP.NET Ajax controls from the Control
I want to send emails in HTML format. How can I use asp.net to
I just wanted to see if I could have your thoughts on the design

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.