0

I just started MVC and I'm having troubles on saving and IList model to database. I have a for loop, looping through a list as suggested by all the posts i've read on how to save multiple items inside the model. However, I cannot see examples or articles on how i can render a partial view just by passing a parameter

This was the original code. Which returns null model on submit.

@foreach (var item in Model) 
            { 
                Html.RenderPartial("_Budget", item); 
            }  

And this is the current code which I found from the suggestions. But I can't figure out how i can render the partial view every loop. Any advise would be appreciated. Thanks.

@for (var i = 0; i < Model.Count; i++) 
            { 
                Html.RenderPartial("_Budget", item); 
            }
igarren
  • 37
  • 2
  • 13
  • 2
    You cant (at least not without some hacks). Use an `EditorTemplate` so that you form controls are correctly named with indexers. Refer [this answer](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943) for an example. –  Oct 17 '16 at 06:24

1 Answers1

0

Try to use @Html.Partial

@foreach (var item in Model) 
{ 
   @Html.Partial("_Budget", item); 
} 
Abdul Hadi
  • 1,229
  • 1
  • 11
  • 20