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.

Thanks

Controller

Function EditEmployeeCoverage(Optional ByVal id As Integer = Nothing) As ActionResult
'id is quote.id
    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 = viewModel.quote.id})
End Function

ViewModel

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

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

<h2>Edit Employee Coverage - @Model.firm.name</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)
        @<fieldset>
            <legend>EmployeeCoverageViewModel</legend>
            <input id="@("Submit" + i.ToString)" type="submit" value="@("Submit" + i.ToString)" />

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

        </fieldset>
    End Using
Next

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 for LastMitch

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)){

  <h4>@item.Text</h4>
  }
  }
  }
  }

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[@quote.id].Id" value="eqDetails[@quote.id].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 for LastMitch

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 ASP.net. But for @foreach code it should look like this:

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

@foreach (var list in Model){
<div>
<span class="list.var">@list.var</span>
<span class="list.var">@list.var</span>
</div>
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.