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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:39:15+00:00 2026-05-16T16:39:15+00:00

Here is my situation – I have two nested view models: <%=Html.EditorFor(x => x.DisplayEntitiesWithRadioboxesViewModel)%><br

  • 0

Here is my situation –

I have two nested view models:

  1. <%=Html.EditorFor(x => x.DisplayEntitiesWithRadioboxesViewModel)%><br />

Which sit within their parent (StructureViewModel), I can populate the nested ViewModels easily and pass it through to the main View:

Within the Controller – Example

var moveDepartment = new StructureViewModel();
moveDepartment.DisplayEntitiesWithRadioboxesViewModel = fullDepartmentList.Select(x => new DisplayEntityViewModel
            {
                Id = x.Id,
                Path = x.Path,
                PathLevel = x.PathLevel,
                Description = x.Description,
            });

return View(moveDepartment);

EditorTemplete – Example

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Site.Areas.Administration.ViewModel.DisplayEntityViewModel>>" %>
<table class="aligncenter"><%
  if (Model != null)
  {
    foreach (var entity in Model)
    {%>
      <tr class="tRow">
        <td style="text-align:left; text-indent:<%=Html.Encode(entity.PathLevel)%>em">
          <%=Html.Encode(entity.Description)%>
          <%=Html.RadioButton("radiobutton",entity.Id)%>
        </td>              
      </tr><%    
    }
  }%>
</table>


namespace Site.Areas.Administration.ViewModel
{
    public class DisplayEntityViewModel
    {
        public int Id { get; set; }
        public string Path { get; set; }
        public string PathLevel { get; set; }
        public string Description { get; set; }   
    }
}

However when I try to pull back this information the nested ViewModels are null:

[HttpPost]
public ActionResult Move(StructureViewModel StructureViewModel)

When I hover over StructureViewModel it only contains data set at the parent ViewModel. For example: a hidden value can been seen but DisplayEntitiesWithRadioboxesViewModel = null.

The only way I know how to access the DisplayEntitiesWithRadioboxesViewModel is to use FormCollection and iterate throught the FormCollection and pull out the information I need from the nested ViewModels.

This however just doesn’t seem right, as I have found at I then have to re-populate the DisplayEntitiesWithRadioboxesViewModel with the values from the FormCollection, if for example an error has occured and the user needs to be sent back to the same View.

I have tried searching the web/books but cannot find a solution.

Is there a better way?

Thanks in advance for any help.

And why did you use an EditorFor for a
simple dropdown, which is easily to
use with DropDownFor

This has now been altered to use the DropDownFor.

what is the Key of the
DisplayEntitiesWithRadioboxesViewModel
value in FormCollection

{string[3]}
[0] = "DisplayEntitiesWithRadioboxesViewModel.radiobutton"
[1] = "Action"
[2] = "OldParentId"

Clare 🙂

  • 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-16T16:39:15+00:00Added an answer on May 16, 2026 at 4:39 pm

    Your problem is pretty common and somewhat easy to fix once you understand how it works.

    Right now you have a view model that has a property which is an IEnumerable<T> (doesn’t matter what the generic parameter is).  You are trying to pass the items to the view and populate the IEnumerable<T> with the same values when the response comes back, using the values originally written to the page, and augmented with the selected item (at least from the code you have posted anyway, it would help for you to state your exact intention in the question).  The problem you have here is that you must send those values to the page in a way in which they can be returned.

    Let me just say now that you probably should NOT be using this technique.  It is typically a much better idea to return the selection only and generate the list again if you need to server side.

    From the looks of things, you want to return the whole list and then look for the item that is selected, which is after all the point of a drop down or radio button group.  In order to get the selection back, the parameter to your controller action must have properties which match the variables passed back in.  In this case, it looks like you are using the parameter name radiobutton for all of your radio buttons (the same hold true for drop down list, only it uses the name of the list).  Which ever one is selected, the value associated with it is returned with that name.  The MVC framework takes care of trying to find the appropriate action which has as many names specified as possible.  

    What you need to use for your action parameter is a new class that contains a property for all of the field names being submitted back to the server!  Or of course you could simply add the radiobutton property to your StructureViewModel too.  In fact, you’ll notice that it is trying to set that value already, only it doesn’t currently exist on your view model.  You still will not receive the original list back however, but thats okay, because even if you did receive the original list back, you have no identifier on it to let you know which item was selected!

    Hopefully this helps you understand what is going on, if you have more questions, please ask.

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

Sidebar

Related Questions

No related questions found

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.