0

Hi,

It seems that this should be very simple, but I can't make it work. I pass a list of items to the view, edit some of the fields, and post the edited list back to the controler. They go to the view fine, but I am unable to get at the posted model. Could someone point me in the right direction. I am a bit of a novice in this area. Thanks

View:

@ModelType IEnumerable(Of gbip_new.quoteDetails_Result)


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


@Using Html.BeginForm()
     @Html.ValidationSummary(True)
@<fieldset>
    <legend>Quote</legend>
    <table>
        <tr>
            <th>
                @Html.DisplayNameFor(Function(model) model.employeeId)
            </th>
            <th>
                @Html.DisplayNameFor(Function(model) model.employeeName)
            </th>
            <th>
                @Html.DisplayNameFor(Function(model) model.bundleId)
            </th>
            <th>
                @Html.DisplayNameFor(Function(model) model.bundleDescription)
            </th>
            <th>
                @Html.DisplayNameFor(Function(model) model.packageId)
            </th>
            <th>
                @Html.DisplayNameFor(Function(model) model.packageContents)
            </th>
            <th></th>
        </tr>

        @For Each item In Model
            Dim currentItem = item

            @<tr>
                <td>
                    @Html.DisplayFor(Function(modelItem) currentItem.employeeId)
                </td>
                <td>
                    @Html.DisplayFor(Function(modelItem) currentItem.employeeName)
                </td>
                <td>
                    @Html.EditorFor(Function(modelItem) currentItem.bundleId)

                </td>
                <td>
                    @Html.DisplayFor(Function(modelItem) currentItem.bundleDescription)
                </td>
                <td>
                    @Html.EditorFor(Function(modelItem) currentItem.packageId)
                </td>
                <td>
                    @Html.DisplayFor(Function(modelItem) currentItem.packageContents)
                </td>
            </tr>
        Next
    </table>
    <p>            
        <input type="submit" value="Save" />
    </p>
</fieldset>
End Using

Model (Generated)

Partial Public Class QuoteDetails_Result
    Public Property id As Integer
    Public Property corpId As Nullable(Of Integer)
    Public Property quoteId As Nullable(Of Integer)
    Public Property employeeId As Nullable(Of Integer)
    Public Property bundleId As Nullable(Of Integer)
    Public Property packageId As Nullable(Of Integer)
    Public Property soldDate As Nullable(Of Date)
    Public Property createDate As Nullable(Of Date)
    Public Property effectiveDate As Nullable(Of Date)
    Public Property renewalDate As Nullable(Of Date)
    Public Property processDate As Nullable(Of Date)
    Public Property typeId As Nullable(Of Integer)
    Public Property firstName As String
    Public Property lastName As String
    Public Property middleName As String
    Public Property employeeName As String
    Public Property bundleContents As String
    Public Property bundleDescription As String
    Public Property packageContents As String
    Public Property packageDescription As String
End Class

Controler:

        <HttpPost()> _
        Function QuoteDetails(ByVal eqDetails As IEnumerable(Of Global.gbip_new.QuoteDetails_Result)) As ActionResult
            If ModelState.IsValid Then
               'Do Stuff
                Return RedirectToAction("Index")
            End If

            Return View(eqDetails)
        End Function
2
Contributors
1
Reply
8
Views
5 Years
Discussion Span
Last Post by LastMitch
0

It seems that this should be very simple, but I can't make it work. I pass a list of items to the view, edit some of the fields, and post the edited list back to the controler.

You never mention rather you are connected to the database at the same time you never mention was there an error when you ran the code.

Regarding about your form it should look like this:

<% using (Html.BeginForm()) { %>
    <%: Html.TextBoxFor(x => x.employeeId) %>
    <%: Html.TextBoxFor(x => x.employeeName) %>
    <%: Html.TextBoxFor(x => x.bundleId) %> 
    <%: Html.TextBoxFor(x => x.bundleDescription) %>
    <%: Html.TextBoxFor(x => x.packageId) %>
    <%: Html.TextBoxFor(x => x.packageContents) %> 
    <input type="submit" value="OK" />
<% } %>

[HttpPost]
public ActionResult Index(item model)
{
    model.employeeId = "employeeId";
    model.employeeName = "employeeName";
    model.bundleId = "bundleId";
    model.bundleDescription = "bundleDescription";
    model.packageId = "packageId";
    model.packageContents = "packageContents";
    return View(model);
}

You can read more here that can explain more detail how to look at the model from view point:

http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.