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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:32:43+00:00 2026-06-14T22:32:43+00:00

I am working on an MVC project where controller actions deal with Assets. Different

  • 0

I am working on an MVC project where controller actions deal with Assets. Different controllers take in the assetId parameter in different way: Some controllers simply get int assetId, other int id, and other using a complex object AssetDTO dto (which contains a property that holds the assetId)

I am writing an ActionFilter that is added to the action method and is provided with the actionParameter name where I can get the asset value.

Action Method:

    [AssetIdFilter("assetId")]
    public ActionResult Index(int assetId)
    {
            ...
    }

The attribute is defined as:

public class AssetIdFilterAttribute : ActionFilterAttribute
{
    public string _assetIdParameterKey { get; set; }

    public AssetIdFilterAttribute (string assetIdParameterKey)
    {
        _assetIdParameterKey = assetIdParameterKey;
    }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        int assetId;
        if (Int32.TryParse(filterContext.ActionParameters[_assetIdParameterKey].ToString(), out assetId))
        {
                    ......
        }
    }

This works as expected, but will only work when the assetId is provided as a primitive. I am not sure what to do when the assetId is provided within a complex object into the action method.

Will I need to parse each object differently depending on the type? I am hoping I can specify some kind of dot-notation in the AssetIdFilter to tell it where the assetId is located: dto.assetId

Any way I can use dynamics? or reflection?? ect.???

  • 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-14T22:32:45+00:00Added an answer on June 14, 2026 at 10:32 pm

    and here dynamic comes to the rescue.you can change the actionFilterAttribute to be :

            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                dynamic assetIdHolder = filterContext.ActionParameters[_assetIdParameterKey];
                if (assetIdHolder.GetType().IsPrimitive)
                {
                    //do whatever with assetIdHolder              
                }
                else
                {
                    //do whatever with assetIdHolder.assetId
                }
            }
    

    cheers!

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

Sidebar

Related Questions

I working on my first ASP.net MVC project and and i got some problems
I am currently working on an ASP.NET MVC project. Some developers on the team
I have a MVC 4 project I am currently working on and need some
I have started working on an MVC project and I came across some scenarios
I am working on mvc project, with repository pattern and entity framework, now on
I am working on a MVC project and the performance was fine. On application_start
I'm working on a MVC 3 project and CSS has never been my strong
I'm working on a Spring MVC project in which I'm using Hibernate Validator to
I'm working on an ASP.NET MVC project which uses the MarkdownDeep Editor to add
I am lost on this MVC project I am working on. I also read

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.