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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:35:13+00:00 2026-05-19T23:35:13+00:00

I have a custom modelbinder built to handle my accountRequest class. This class consists

  • 0

I have a custom modelbinder built to handle my accountRequest class.
This class consists of some boolean values and a UserViewModel.

The UserViewModel is made up of strings such as Firstname, Last Name, Address.

Originally I was just passing the UserViewModel as the action parameter but I now I need to package UserViewModel inside of accountRequest.

however, now my modelbinder will not map the strings in the httpContext.Request to my UserViewModel inside of AccountRequest. All of the booleans map just fine.

Is there an easy way to get his data to map to the UserViewModel properties other than hardcoding it?

I have attempted this but I dont like it. (simplified)

Dim accountRequest As New AccountRequest
Dim user As New UserViewModel

If Not String.IsNullOrEmpty(controllerContext.HttpContext.Request("Firstname")) Then
  user.FirstName = controllerContext.HttpContext.Request("Firstname")
End If

accountRequest.CurrentUser = user
Return accountRequest

Obviously any help is greatly appreciated. Thanks in advance!

  • 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-19T23:35:13+00:00Added an answer on May 19, 2026 at 11:35 pm

    Sorry – just realised that your code was VB and I’ve answered in C#

    This could be because the model binder is now looking modelname.property instead of just property in the ValueProviders and, previously, because it was a direct action method parameter, it would have just been looking for property.

    Now that the model type is a member of another, its property name will be used as a prefix and I don’t believe you can remove that requirement (could try Bind(Prefix="") on the parameter, but I don’t think that’ll work).

    This is assuming you aren’t custom-binding every property and that the DefaultModelBinder is doing some of these properties for you.

    You should be able to make it work, without changing code, by altering your query string to be ?modelname.property=[value]. If you’re using a Form, then you should consider using the Html.EditorFor extension method – as it takes care of model naming (so long as your ViewModel member names and input model names are consistent). But as an example from the query string:

    public class MyObject{
      public string StringValue { get; set; }
    }
    
    public class MyObjectOuter{
      public MyObject Nested { get; set; }
    }
    
    public ActionResult Index(MyObjectOuter obj);
    

    The obj.Nested.StringProperty value can be filled with: /Index?Nested.StringValue=hello%20world because the obj prefix is implicit anyway.

    If you don’t like this, you have a couple of options:

    1) Change the signature of the method to take two parameters:

    public ActionResult Index(MyObjectOuter outer, MyObject nested)
    

    And then in the body you immediately copy nested to the obj.Nested property. This is a little bit hacky – but it’ll work.

    2) Manually force the bind of your class’ properties to use non-prefixed values from the ValueProviders (but then you’re limiting your model type to only work with certain types of request – which isn’t exactly flexible).

    3) Or, like I said earlier, if these properties are being bound from an Http Form, use Html.EditorFor to generate the markup – it automatically generates inputs with the correct names, so long as they don’t change from input->output.

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

Sidebar

Related Questions

hi i would like to create a custom calendar, this calendar will have custom
I have a custom built ajax [div] based dynamic dropdown. I have an [input]
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
We have a custom-built Flash-based video player that I maintain, and it needs to
I have a custom model class which contains a decimal member and a view
I want to create a custom modelbinder which validates the bounded model. I have
i have this model on mvc: public class User { public string Name {
How would you implement this ? I have the following model : class Something
I have custom coded several enterprise applications for mid to large organizations to use
I have custom errors configured in my web.config, but IIS 6.0 is returning the

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.