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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:25:22+00:00 2026-06-02T20:25:22+00:00

Having some issues trying to model bind to my view model. The basic viewmodel

  • 0

Having some issues trying to model bind to my view model.

The basic viewmodel is thus:

public class RegistrationVM
{
    public TravelHistoryVM TravelHistory {get;set;}
    public UserDetailVM UserDetails {get;set;}
    public ICollection<HandsetDevicesVM> ExistingDevices {get;set;}
}

A wrapper for 3 further viewmodels, each containing the usual band of strings, ints and bools. Ignore the collection of HandsetDevicesVM for now.

I have the following view (sample for clarity)

@using (Html.BeginForm())
{
    @Html.ValidationSummary(false)

    @Html.LabelFor(model => model.TravelHistory.DoNotTravel)
    @Html.CheckBoxFor(model => model.TravelHistory.DoNotTravel)

    @Html.EditorFor(model => model.UserDetails, "UserDetailsHidden")
}

The ‘TravelHistory’ object is being bound fine, no issues.
The ‘UserDetails’ object is always just null when data is posted back.

The template is definitely rendering, I can tell from the HTML. The template itself is given below:

@model Foo.Bar.UserDetailVM
@Html.HiddenFor(model => model.EmailAddress)
@Html.HiddenFor(model => model.FirstName)
@Html.HiddenFor(model => model.Surname)
@* etc etc *@

The HTML generated is

<input data-val="true" data-val-required="The Email Address field is required." id="UserDetails_EmailAddress" name="UserDetails.EmailAddress" type="hidden" value="stack@overflow.com" />
<input data-val="true" data-val-required="The First Name field is required." id="UserDetails_FirstName" name="UserDetails.FirstName" type="hidden" value="Stack" />
<input data-val="true" data-val-required="The Surname field is required." id="UserDetails_Surname" name="UserDetails.Surname" type="hidden" value="Overflow" />

I am using this EditorTemplate on another view with no issues (it binds to that viewmodel no problem).

Finally, using Fiddler I can ascertain the information is being posted.. I think

UserDetails.EmailAddress=stack%40overflow.com.test&UserDetails.FirstName=stack&UserDetails.Surname=overflow

Any ideas? Where should I be concentrating my debugging efforts?

Edit1: just noticed this from the ModelState object

AttemptedValue: 'Foo.Bar.UserDetailVM'

So it seems it is trying to bind the string value ‘Foo.Bar.UserDetailVM’ to the object and (obviously) failing.

Edit2:

[HttpPost]
public ActionResult Travel(RegistrationVM model)

As requested, the action I am POSTing to

Edit3:

Ahhh.. OK going back a stage, this is the action method that serves up the View

[HttpGet]
public ActionResult Travel(PreRegistrationVM model)
{
    if (TempData["PreRegistrationVM"] != null)
    {
        model = (PreRegistrationVM)TempData["PreRegistrationVM"];
    }
    var newModel = new RegistrationVM(model);
    return View(newModel);
}

This is what I have been using (and thus has been part of the process that does not work). Essentially the information from a prior step is saved in the TempData and picked up in this method. It is then used to instantiate the VM as above. At this point (if I insert a breakpoint here), the model is populated with data as I expect.

If I amend that to the following:

[HttpGet]
public ActionResult Travel(PreRegistrationVM model)
{
    var newModel = new RegistrationVM 
    {
        FirstName = "Stack",
        Surname = "Overflow"
    };
    return View(newModel);
}

It binds as expected. Is TempData the culprit here?

  • 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-02T20:25:24+00:00Added an answer on June 2, 2026 at 8:25 pm

    Quick background check: this was a problem encountered whilst creating a ‘wizard’ step by step registration process. I wanted to avoid saving information to the database until the registration was completed. Hence, the idea was to use the TempData collection to store information between Actions, and to use RedirectToAction to move from step to step.

    For what it is worth, I amended the method from using TempData like so

    [HttpGet]
    public ActionResult Travel(PreRegistrationVM model)
    {
        if (TempData["PreRegistrationVM"] != null)
        {
            model = (PreRegistrationVM)TempData["PreRegistrationVM"];
        }
        var newModel = new RegistrationVM(model);
        return View(newModel);
    }
    

    To retrieve the information from the database once per step in the registration process.

    [HttpGet]
    public ActionResult Travel(int id)
    {
        var model = FooRepository.GetById(id);
        return View(model);
    }
    

    I’m not entirely sure why the TempData approach resulted in this, would be interested in people more learned than I offering reasons.

    Thanks for all who answered, helped me track it down.

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

Sidebar

Related Questions

I'm having some issues trying to get the top 5 of my tutorial model
I'm having some issues when trying to bind a property of a UserControl in
I am having some serious issues trying to tweak my layout in a table.
I'm trying to get started with twitter4r but I'm having some issues: Why I
I am new to codeigniter and I am having some issues loading a model
I'm having some issues trying to test elements inside a RichFaces modal panel, as
Having some issues trying to create a fixed header layout for this jsfiddle: http://jsfiddle.net/4xk4D/107/
I'm having some issues trying to extract all the email headers in python. I
I'm having some issues because I'm trying to re-use code (which can be used)
I am having some issues getting my JS to work right. I am trying

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.