I have this issue every now & then and I never know how to properly and easily fix it. So please help me once and for all!

My form(cihForm) is not binding to the view. Once i load the view, add text to the two input boxes, and click my 'save' button the debugger goes to my "New" constructor in the FormsViewModel > Populates the Clubs and Categories as it should, once it is finished there the debugger goes to my Create_Post function in the 'controller'.

Once it is inside the HTTPpost action my model has clubs and categories as it should, but the form is empty. All of my fields have 'nothing' or default data assigned to it.

Model

Public Class FormsViewModel
    Public form As cihForm = New cihForm()
    Public Clubs As List(Of cihOrganizationSub) = New List(Of cihOrganizationSub)
    Public Categories As List(Of cihCategoryOrgDef) = New List(Of cihCategoryOrgDef)

    Public Sub New()
        Dim lists As cihLists = New cihLists()

        'Clubs
        lists.loadOrganizationSubs(ZenCommon.CurrentOrgId, ZenCommon.CurrentUserId)
        Clubs = New cihOrganizationSubList(ZenCommon.CurrentOrgId, ZenCommon.CurrentUserId).subList

        'Categories
        lists.loadCategoryOrgDef(ZenCommon.CurrentOrgId)
        Categories = lists.organizationClubCategories

    End Sub
End Class

Controller

<HttpGet>
<ActionName("Create")>
Function Create_Get() As ActionResult
    Dim viewModel As FormsViewModel = New FormsViewModel()
    Dim emptyList() As String = {}

    'List of Orgs
    ViewBag.SubOrgList = New SelectList(viewModel.Clubs, "subId", "codDescr", viewModel.form.selectedSubOrgId)

    'List of Events
    Dim search As cihEventSearch = New cihEventSearch(ZenCommon.CurrentOrgId, "", Date.Now.AddMonths(-1), Date.Now.AddMonths(1), True, emptyList, emptyList, emptyList)
    ViewBag.EventList = New SelectList(search.eventList.OrderByDescending(Function(evt) evt.startUtc), "eventId", "eventTitle", viewModel.form.selectedEventId)

    ViewBag.HideRightColumn = True
    ViewBag.BodyClass = "span10"

    Return View()
End Function

<HttpPost>
<ActionName("Create")>
Function Create_Post(form As FormsViewModel) As ActionResult

    Return View()
End Function

View

    @ModelType MVCProject.FormsViewModel
    @Using Html.BeginForm()
        @Html.TextBoxFor(Function(model) model.form.Title, New With {.placeholder = "Title", .class = "hideOffFocus input-full large-type"})
        @Html.TextAreaFor(Function(model) model.form.Description, New With {.placeholder = "Description", .class = "hideOffFocus input-full"})

<input type="submit" name="cmdSave" value="Save" id="cmdSave" class="btn btn-primary" />
    End Using

Related posts

Recent Viewed