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

  • Home
  • SEARCH
  • 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 8521209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:45:22+00:00 2026-06-11T06:45:22+00:00

I would like make a pretty simple in my mind but really complicated when

  • 0

I would like make a pretty simple in my mind but really complicated when I tried to create. In a MVC ASP.NET environnement, I want to create one model but render it many times. It’s work but when I want get back datas I have nothing.
The model look like this:

public class HardwareModel
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    ...
}

The wrapper look like:

public class WrapperModel
{
    public List<HardwareModel> HardwareList { get; set; }

    public WrapperModel()
    {
        HardwareList = new List<HardwareModel>();
    }
}

The controller:

readonly Hardware _hardware = new Hardware();
    [Authorize]
    public ActionResult Index()
    {
        return View(_hardware.GetHardwareList(int.Parse(Session["idEmployee"].ToString())));
    }

    [HttpPost]
    [Authorize]
    public ActionResult Index(WrapperModel model)
    {
        return View(model);
    }

And the view:

<% using (Html.BeginForm())
   {%>
<% foreach (var hardware in Model.HardwareList)
   {%>    
    <tr>
        <td>
            <div class="editor-label">
                <%: Html.LabelFor(m => hardware.SelectedHardwareType) %>
            </div>
            <div class="editor-field">
                <%: Html.DropDownListFor(m => hardware.SelectedHardwareType, hardware.Hardwaretypes) %>
            </div>
...

So the result is something like this:
View Result

The render is exactly what I want but the problem is that when I push a save button, the second part of the controller is used but the value of “WrapperModel model” is a empty List. In the Request value, I can see that everything is send to the controller but nothing match in the WrapperModel.

I don’t know what to do because the number of “HardwareModel” can be 0 or 99 so I can’t create HardwareModel1, HardwareModel2 … like I read on web.

thanks for helping me and sorry for the long post.

  • 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-11T06:45:24+00:00Added an answer on June 11, 2026 at 6:45 am

    Use an EditorTemplate and you will be good.

    Create a Folder called EditorTemplates annd Create aa view (the editortemplate) with the name
    HardwareModel.cshtml

    enter image description here

    Now add the below code to the editor template (the new view). You may update the layout according to your requirement.

    @model HardwareModel           
    <p>
     Name @Html.TextBoxFor(x => x.Name) <br />
     Desc : @Html.TextBoxFor(x => x.Description)
     @Html.HiddenFor(x => x.Id)
    </p>
    

    Now in your Main View, Use the Html.EditorFor HTML helper method to call this editor template.

    @model WrapperModel
    @using (Html.BeginForm())
    {       
      @Html.EditorFor(x=>x.HardwareList)
      <input type="submit" value="Save" />    
    }
    

    Assuming you have the GET Action sending a list of HardwareModels to the View like this

    public ActionResult Hardware()
    {
        WrapperModel model = new WrapperModel();
        //HardCoded for demo.Can be replaced with entries based on your DB data
        model.HardwareList.Add(new HardwareModel { Id=1, Name = "Printer", 
                                                         Description = "desc" });
        model.HardwareList.Add(new HardwareModel { Id=2, Name = "Scanner",
                                                         Description = " desc2" });
        return View(model);
    }
    

    Now your HttpPost action method will get the Child Properties on form submit

    [HttpPost]
    public ActionResult Hardware(WrapperModel model)
    {
        //check for  model.HardwareList Property here;
        return View(model);
    }
    

    enter image description here

    Here you can download a working sample which i wrote to address your question.

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

Sidebar

Related Questions

I would like to make my app freeware, but if a user is willing
I would like to make register button, but when people click on it. A
What I want to do is pretty simple. I would like to have sync
This ought to be pretty simple, maybe use a regex but I would think
I would like make a script using PHP (probably need JS) to send POST
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make sure my classes are robust - even if they
I would like to make a password and username entry field. And a submit
I would like to make a JSF inputText field into upper case when 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.