The model is not overly complex. It has a list of items each of which is generated in its own form with its own submit button. Each submit button has its onw id. The first form returns what I need. When I view the results from the form, if I have selected the first record, I get a single item in eqDetails containing the information from the form. Any other item sends back nothing. I have tried miving the submit buttom to the template and returning the detail model, but that did not return anything. Examining the page source shows that each form's submit button does have a unique id. If none brought back data I am sure I would be less confused. Any ideas and thoughts are welcome. I will need a separate form for each employee, as I will eventually need to set only one to edit at a time.



Function EditEmployeeCoverage(Optional ByVal id As Integer = Nothing) As ActionResult
'id is
    Dim viewModel As New EmployeeCoverageViewModel(id)

    Return View(viewModel)
End Function

<HttpPost()> _
Function EditEmployeeCoverage(ByVal viewModel As EmployeeCoverageViewModel) As ActionResult
    Return RedirectToAction("EditEmployeeCoverage", New With {.id =})
End Function


Public Class EmployeeCoverageViewModel
    Public Property productTypes As List(Of ProductType)
    Public Property qtEmployees As List(Of EmployeeQuote)
    Public Property eqDetails As New List(Of EmployeeCoverageDetailRecord)
    Public Property qtBlended As String
End Class

Public Class EmployeeCoverageDetailRecord
    Public Property empId As Integer
    Public Property empName As String
    Public Property empMonIncome As Integer
    Public Property quoteId As Integer
End Class

**View - **

@ModelType gbip_new.EmployeeCoverageViewModel

    ViewData("Title") = "EditEmployeeCoverage"
End Code

<h2>Edit Employee Coverage -</h2>

Note that caps can be adjusted down, but can not be adjusted above the limit set by an ewployees monthly income

<br />
Edit @Model.qtBlended Coverage

<h3>Effective Date: @Html.DisplayFor(Function(model) model.quote.effectiveDate)</h3>

<hr />

@For count = 0 To Model.eqDetails.ToList.Count - 1
    Dim i = count

    @Using Html.BeginForm("EditEmployeeCoverage", "EmployeeQuote", FormMethod.Post)
            <input id="@("Submit" + i.ToString)" type="submit" value="@("Submit" + i.ToString)" />

            @Html.EditorFor(Function(Model) Model.eqDetails(i)) 

    End Using

Editor Template for Detail View

@ModelType gbip_new.EmployeeCoverageDetailRecord

@Html.HiddenFor(Function(model) model.empId)           
@Html.HiddenFor(Function(model) model.quoteId) 
@Html.EditorFor(Function(model) model.empName)
Member Avatar

Razor MVC Binding Problem - only 1st item in list binds

I assume that this is drop down list?

You can add this to see rather the binding works or not:

  if(Model.SelectedValues != null){

  foreach (var item in Model.eqDetails){

  if(Model.SelectedValues.Exists(value => value == eqDetails.Value)){


I'm just curious why did you create a input tags like this:

 <input id="@("Submit" + i.ToString)" type="submit" value="@("Submit" + i.ToString)" />

Isn't it much easier to separate it?

 <input type="text" id="eqDetails[].Id" value="eqDetails[].Id" />

 <input type="submit" value="submit" runat="server" />

It just never occured to me. Yes it is easier. That would not affect binding though; would it?

Member Avatar

That would not affect binding though; would it?

Did you ran the code? If it doesn't bind for 2nd item then it has to do with the @foreach not looping.

I don't think you didn't post that part regarding about your list. It werid that you can get the 1st item not the second.

I'm not familiar with VB code mixing with But for @foreach code it should look like this:

@model IList<list><h3>List Index</h3>

@foreach (var list in Model){
<span class="list.var">@list.var</span>
<span class="list.var">@list.var</span>