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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:27:43+00:00 2026-06-01T21:27:43+00:00

For example: class MyContoller { [MyCustomAttribute] public ActionResult MyAction(ModelX fromRequest, ModelY fromSession, ModelZ fromCookie)

  • 0

For example:

class MyContoller
{
    [MyCustomAttribute]
    public ActionResult MyAction(ModelX fromRequest, ModelY fromSession, ModelZ fromCookie)
    {
       string productId = fromRequest.ProductId;
       string userId = fromSession.UserId;
       string cultureName = fromCookie.CultureName;
    }
}

Reason:

I don’t want to visit Request, Session and HttpContext in the controllers, and the default idea of MVC3 which passing models to actions is very great.

I want the number of parameters of MyAction is easy to change. For example, if I add a new parameter, the system will try to look for values in Request, Session or Cookies by the name or type of the parameter (I think custom ModelBinders may be required for cookie values) and pass the filled model to my action. I don’t have to write extra code.

Can the custom attribute (MyCustomAttribute in the example) accomplish this idea?

  • 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-01T21:27:45+00:00Added an answer on June 1, 2026 at 9:27 pm

    I am not sure I follow you about the custom attribute. What are you expecting the custom attribute to do?

    Yes, an action method can take as many model parameters as you want. Obviously, only one can be bound in any given request (because a view can only have one model). Whichever one is found first will be bound, and the others will be null.

    So let’s say you have the following:

    public class ModelX {
        public string X {get;set;}
    }
    
    public class ModelY {
        public string Y {get;set;}
    }
    
    public class ModelZ {
        public string Z {get;set;}
    }
    

    And you have an action method like this:

    public ActionResult DoIt(ModelX x, ModelY y, ModelZ z)
    {
        return View();
    }
    

    And in your DoIt.cshtml you have the following:

    @model ModelZ
    
    @using(Html.BeginForm()) {
        @Html.TextBoxFor(x => x.Z)
        <input type="submit"/>
    }
    

    If you type something into the textbox and submit, then the model binder will bind a ModelZ with the value you entered and ModelX and ModelY will be null.

    If you mean can an action method bind multiple models simultaneously, then I would have to ask you.. How exactly do you plan to have a view have more than one model? You can certainly create a wrapper model to contain the multiple models, but a view can only have one.

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

Sidebar

Related Questions

I have an example class public class MyClass{ ActionResult Method1(){ .... } [Authorize] ActionResult
Example: class C { public: void operator =(int i) {} }; class SubC :
I have an example class containing two data points: public enum Sort { First,
Here is code example class A{ int i; public: A(int i) : i(i) {}
Example class code: <?php class example { public function forExample() { return true; }
Simple class for example: class Foo { protected $_bar; public function setBar( $value )
I have the following example-class: public class MyClass<T> { public IList<T> GetAll() { return
Example: Class A { public function __construct() { $this->b_Instance = new B(); } public
Example: class myExample { public function example_fn() { $example_val = $this->some_fn(); _debug( $example_val, _get_position()
Example: class MyRecursiveIteratorIterator extends RecursiveIteratorIterator{ public function current(){ echo 'START'; return parent::current(); } }

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.