Member 11871625 Ответов: 0

Asp. Net MVC controler


Hello,

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"


Что я уже пробовал:

Public Class ProduitViewModel
    <Display(Name:="Produit")> _
    Property OrgList = New List(Of ProdDataModel)
 
 
    <Required> _
    Public Property SelectedValueProd() As String()
        Get
            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)
        Get
            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
        Get
            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
        Get
            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
        Get
            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
            listProd.OrgList.add(prod)
        Next
        Return View(listProd)
    End Function

Member 7870345

Привет:
Не могли бы вы включить код в view/html concernig в форму, относящуюся к ProdView?
Без этого я не могу понять, что могло бы произойти?
Спасибо йой

Member 11871625

Большое спасибо!.

Ниже кода

Member 11871625



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

@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")


@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
<h2></h2>

<div class="row">
<div class="col-md-8">
<section id="TraitementForm">
@Using (Html.BeginForm())
@<text>
@Html.ValidationSummary(True)
<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>
</div>

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

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

</div>

@ModelType ProduitViewModel
@Code
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

Мне очень жаль,но я не понимаю кода.
Возможно, это поможет вам: Контроллер должен иметь параметр, соответствующий модели данных, соответствующих поданной форме

Попробуйте сделать вот что: объявите свой контроллер:
Функция ProdView(listProd как ProduitViewModel) Как ActionResult
и удалите объявление 'Dim listProd As New ProduitViewModel' в теле функции

Надеюсь, что это вам поможет.

0 Ответов