2017-06-22 1 views
0

J'ai un modèle actuel de la liste des factures que je veux lier à une liste de sélectionliste Sélectionner ne pas poster option sélectionnée au contrôleur

public class InvoiceList 
{ 
    public string InvoicerReference { get; set; } 
    public Invoice SelectedInvoice{ get; set; } 
    public List<Invoice> Invoices { get; set; } 
} 

Et voici le menu déroulant de la vue

@using (Html.BeginForm("Invoice", "Billing", FormMethod.Post)) 
{ 
    @Html.DropDownListFor(m => m.SelectedInvoice, new SelectList(Model.Invoices, "invoiceReference", "InvoiceDisplay")) 
    <input type="submit" id="btnSelectInvoice" /> 
} 

Cependant quand je poste à mon contrôleur le modèle est nul

public ActionResult Invoice(InvoiceList invoiceReference) 
{ 
    .... 
    return View(invoiceList); 
} 

Quelqu'un peut-il voir ce que je fais de façon incorrecte ?

Répondre

0

Votre problème est ici:

public Invoice SelectedInvoice{ get; set; } 
@Html.DropDownListFor(m => m.SelectedInvoice 

Le Html.DropDownListFor attend que le premier paramètre soit du type de value des options.
Ainsi, si votre invoiceReference, est, par exemple, un int, vous feriez ceci:

public class InvoiceList 
{ 
    public string InvoicerReference { get; set; } 
    public int SelectedInvoice{ get; set; } 
    public List<Invoice> Invoices { get; set; } 
}