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 8075265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:56:01+00:00 2026-06-05T14:56:01+00:00

I am trying to implement a requirement that will allow me to change the

  • 0

I am trying to implement a requirement that will allow me to change the state of an html control based on the users role or other business logic. For example some users should not be able to edit a certain model property or in some cases I do not even want the control to render to the html DOM.

Within the HTML helpers the Metadata can tell the helper whether or not to render a control or it can make it read-only/disabled. Rather than re-invent the wheel here I just want to use what is already in place by changing the metadata within an action filter based on logic at run time. I do not want this logic within my view and I do not want to have to create custom helpers for every single html control if I do not have to..

What I was trying to do was create an action filter to handle evaluating logic rules in my business layer and then make changes to the metadata for a given model.property.

The problem is that my modifications to the metadata do not seem to be making it to the view. It almost seems like my changes to the metadata within the action filter are not by reference so therefore I am not modifying the same instance that is used for the view?

public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
    var trans = filterContext.Controller.ViewData.ModelMetadata.Properties.Where(e => e.PropertyName == "Transaction").FirstOrDefault();
    trans.DisplayName = "Show FOO!";
}

What am I doing wrong?

  • 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-05T14:56:03+00:00Added an answer on June 5, 2026 at 2:56 pm

    You cannot change the ModelMetadata.Properties values in a filter in fact you cannot change them at all.

    The problem is inside the built in DataAnnotationsModelMetadataProvider (to be precise AssociatedMetadataProvider‘s GetMetadataForProperties method) namelly the ModelMetadata.Properties gets regenerated from the attributes every time you iterate over it.

    So the items inside the ModelMetadata.Properties collection are immutable.

    You can check it with debugging:

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
         var properties = filterContext.Controller.ViewData.ModelMetadata.Properties
         var trans1 = properties.Where(e => e.PropertyName == "Transaction").First();
         trans1.DisplayName = "Show FOO!";
         var trans2 = properties.Where(e => e.PropertyName == "Transaction").First();
    }
    

    The trans1 and trans2 will be different instances (you can check their hashcode) so trans2 displayname will be the original displayname not “Show FOO!”.

    So you need to Extend/Write the a new MetadataProvider to achieve your goal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement some nested loops that are spitting out good old nested html
I am trying to implement something similar to the flight control game. There will
I'm trying to implement a design in CSS that will have a tiled background
I'm trying to implement a requirement in our system that all strings be trimmed
Trying to implement a rating system of users and postings. What is the best
when trying to implement an Aspect, that is responsible for catching and logging a
I'm trying to implement a SessionState server to allow multiple web servers to share
Due project requirements, I need to create a webapp that, when executing, will allow
I'm trying to implement ellipsis in Umbraco, the requirement being 15 characters of intro
I'm trying to implement an industry spec that requires enveloped XML digital signatures (XMLDSIG).

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.