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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:09:59+00:00 2026-05-25T23:09:59+00:00

I have a view that – among other things – contains a list of

  • 0

I have a view that – among other things – contains a list of elements. I want to reuse this list, so I move it out to a partial view. My view contains a form, and on post I want to include some values in the list. Therefore I use @Html.EditorFor(m => m.Something) to generate input-boxes which will get a unique Id. The view is strongly typed to use “MyModel” as Model. On post the MVC framework handles everything very well – putting the values back together to a MyModel object containing the input and some fields I used Html.HiddenFor on. All good.

Now I move this to a partial view. The partial view only works on the list and therefore is strongly typed to model List. I include this view from my main view, and pass in the list I want it to render. The table code inside the partial view is exactly what it was before except that it is changed to get values from the list instead of MyModel. All data is displayed perfectly, but there is a problem. The input-boxes doesn’t get an Id any more. And because they don’t get an Id their value isn’t included in the posted form – and hence they don’t appear in the model I get as input to my post method. I tried including the partial view using both @Html.Partial("_MyPartial", Model.Items) and @{Html.RenderPartial("_MyPartial", Model.Items);}

So the question is; how can I make this work with a partial view? How can I get that Id back?

Here is some sample code in case anything is unclear:

MyModel.cs
----------
public class MyClass 
{ 
    public string Val1 { get; set; }
    public string Val2 { get; set; }
}

public class MyModel
{
    public List<MyClass> Items {get; set; } 
}

MyView.cshtml: 
--------------
@model MyModel
using (Html.BeginForm("SomeAction", "SomeController", FormMethod.Post))
{
    @Html.Partial("_MyPartial", Model.Items)
}

_MyPartial.cshtml: 
------------------
@model List<MyClass>

<table>
    <tbody>
    for (var i = 0; i< Model.Count; i++)
    {
        <tr>
            <td>
                @Model[i].Val1
                @Html.HiddenFor(model => model[i].Val1)
            </td>
            <td>@Html.EditorFor(model => model[i].Val2)</td>
        </tr>
    }
    </tbody>
</table>
  • 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-25T23:10:00+00:00Added an answer on May 25, 2026 at 11:10 pm

    You will have to use EditorFor for your Model.Items as well.
    So change the _MyPartial to something more relevant, like MyEditorForMyClass.cshtml.
    Make a ‘EditorTemplates‘ folder in the Shared or the folder you’re working in and place the ‘MyEditorForMyClass.cshtml‘ file in there.

    Then do the following:

    MyView.cshtml: 
    
    --------------
    @model MyModel
    using (Html.BeginForm("SomeAction", "SomeController", FormMethod.Post)
    {
        @Html.EditorFor(model => Model.items,"MyEditorForMyClass"}
    
    }
    

    The EditorFor templates/helper methods allows you to render both standard data-types and your own complex objects that contain multiple properties.

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

Sidebar

Related Questions

I have a view that will look like this: I'm trying to figure out
I have a view that I want to be converted into JSON. What is
I have a view that contains two NSTextFieldCell s. The size at which these
I have a View that renders something like this: Item 1 and Item 2
I have written a partial view that displays a list of rows, where some
I have a view that pushes another view with navigation controller. In this second
I have view that contains a table with the following structure: <table id=mappings> <thead>
I have a view that render itself from a Collection: render: function() { $(this.el).html(JST['templates/menu']({collection:
I have a view that looks like this: And I display a pop up
I have a view that contains a javascript function that i need to init/call

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.