Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm new to this forum.

I start with the MVC.

I tried to rephrase my question.

I need your help.

I display in a multi-selection drop-down list all the products of a connected user.

The user entered a date and validates a form.

In my controler the value of my model is always "NOTHING"

What I have tried:

Public Class ProduitViewModel
    <Display(Name:="Produit")> _
    Property OrgList = New List(Of ProdDataModel)
    <Required> _
    Public Property SelectedValueProd() As String()
            Return p_SelectedValueProd
        End Get
        Set(value As String())
            p_SelectedValueProd = value
        End Set
    End Property
    Private p_SelectedValueProd As String()
    <Required> _
     <Display(Name:="Organisme")> _
    Public ReadOnly Property listOrg() As IEnumerable(Of SelectListItem)
            Return New MultiSelectList(OrgList, "ValueProd", "TextProd")
        End Get
    End Property
    Private p_listOrg As IEnumerable(Of MultiSelectList)
End Class
Public Class ProdDataModel
    Public Property ValueProd As String
            Return p_ValueProd
        End Get
        Set(value As String)
            p_ValueProd = value
        End Set
    End Property
    Private p_ValueProd As String
    Public Property TextProd As String
            Return p_TextProd
        End Get
        Set(value As String)
            p_TextProd = value
        End Set
    End Property
    Private p_TextProd As String
    Public Sub New(valueProd As String, textProd As String)
        p_ValueProd = valueProd
        p_TextProd = textProd
    End Sub
End Class
Public Class ValidationViewModel
    <Required(ErrorMessage:="La date est obligatoire")> _
    <Display(Name:="Date ")> _
    Public Property DateValidation() As String
            Return p_DateValidation
        End Get
        Set(value As String)
            p_DateValidation = value
        End Set
    End Property
    Private p_DateValidation As String
End Class
Public Class ValidationDataModel
    Public Validation As ValidationViewModel
    Public Property prod() As ProduitViewModel
End Class

'Validate Data:
 Function Index(model As ValidationDataModel) As ActionResult
        Dim t As Integer = CInt(model.Validation.DateValidation)
        Return View(model)
    End Function
'Bind DropDown LIST
 Function ProdView() As ActionResult
        Dim loginViewModel As LoginViewModel = New LoginViewModel()
        Dim listProd As New ProduitViewModel
        Dim listProdUser As List(Of ProdDataModel) = loginViewModel.ListeProduit
        For Each prod As ProdDataModel In listProdUser
        Return View(listProd)
    End Function
Member 7870345 2-Jan-17 6:33am    
Could you include the code in the view/html concernig to the form that relates to ProdView?
Without this, I can´t figure what could happen?
Thank yoy
Member 11871625 2-Jan-17 8:51am    
thank you very much.

Below the code
Member 11871625 2-Jan-17 7:38am    

@ModelType ValidationDataModel
ViewData("Title") = "ValidationProd"
End Code
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-multiselect.css" rel="stylesheet" />



<div class="row">
<div class="col-md-8">
<section id="TraitementForm">
@Using (Html.BeginForm())
<div class="form-group">
@Html.LabelFor(Function(model) model.validation.DateValidation, New With {.class = "control-label col-md-2"})
<div class="col-md-10">
@Html.TextBoxFor(Function(model) model.validation.DateValidation, New With {.class = "form-control date-picker", .placeholder = "Choisir une date"})
@Html.ValidationMessageFor(Function(model) model.validation.DateArrete)

<div class="form-group">
@Html.LabelFor(Function(model) model.Prod.ProdList, New With {.class = "control-label col-md-2"})
<div class="col-md-10">

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Validation" class="btn btn-default" />
End Using


@ModelType ProduitViewModel
ViewData("Title") = "ProduitView"
End Code

@Html.DropDownListFor(Function(model) model.listProduit, TryCast(Model.ProduitList, MultiSelectList), New With {.class = "form-control", .multiple = "multiple", .placeholder = "Choisir", .id = "Produit"})
Member 7870345 3-Jan-17 11:02am    
I´m sorry, but i don´t understand the code.
Perhaps this will help you: The controller must have a parameter that conforms the model of the data corresponding to the form submited

Try with this: declare your controller:
Function ProdView(listProd as ProduitViewModel) As ActionResult
and delete the declaration of 'Dim listProd As New ProduitViewModel' in the body of the function

Hope that it will help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900