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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:43:12+00:00 2026-05-27T11:43:12+00:00

Okay, lets say I have a URL like so, which is mapped via HTTP

  • 0

Okay, lets say I have a URL like so, which is mapped via HTTP verb GET to the controller action I have below:

GET /foo/bar?sort=asc&r=true

How can I bind this to my model Bar on my controller action I have below:

class Bar {
    string SortOrder { get; set; }
    bool Random { get; set; }
}

public ActionResult FooBar(Bar bar) {
    // Do something with bar
    return null;
}

Note that the property names won’t and can’t necessarily match the names of the URL parameters. Also, these are OPTIONAL url parameters.

  • 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-27T11:43:13+00:00Added an answer on May 27, 2026 at 11:43 am

    The model binder matches the parameters it gets from the view to the model you have in the action by the Names, so if they won’t match the binding will not work.

    options you got:

    1. Match the inputs names to the model properties names… but You said you can’t do this, (for some unknown reason).
    2. Write custom Model Binder. *
    3. Use The Bind attribute with prefix – though it’ll still force you to have input names close to the model properties names.

    so basically, You can’t do exactly what you want.


    Update:

    You wrote in a comment that the properties CAN match the parameters names, so instead of write custom attributes that maybe will succeeded to do the binding, just write a ViewModel (The VM fromMVC…) to adjust the url parameters names.

    Writing custom model binder is not recommended by the MVC team:

    In general, we recommend folks don’t write custom model binders because they’re difficult to get right and they’re rarely needed
    from here

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

Sidebar

Related Questions

Okay, let's say you have something like this: <span class=image style=background-image: url('http://www.example.com/images/image1.png')></span> Every CSS
Okay, let's say we have a class defined like public class TestClass { private
Okay lets say I have a list, and I want to check if that
Okay, so basically lets say i have a matrix: matrix([[0, 1, 2, 3, 4],
Okay, lets say I have the following text... <h2><a name=test1></a>Test 1</h2>test 1 text <h2><a
How can I re-use a function? Okay lets say I have this main function
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's
Lets say we have 3 tables (actually I have 2 at the moment, but
Okay, so let's say I have a class file called Orange, and then two
Let's say I have an NSSecureTextField in my app. Is it okay for me

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.