Click here to Skip to main content
14,735,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The model item passed into the dictionary is of type 'STOCK_4_MVC.Models.PS_Details_facture_Liste_Result', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[STOCK_4_MVC.Models.PS_Details_facture_Liste_Result]'.


What I have tried:

namespace STOCK_4_MVC.Controllers
{
    public class DetailsFaController : Controller
    {
        Stock_4_MVCEntities db = new Stock_4_MVCEntities();
        // GET: DetailsFa
        public ActionResult Index(int? ref_facture)
        {
            PS_Details_facture_Liste_Result obj = new PS_Details_facture_Liste_Result();
            obj = db.PS_Details_facture_Liste(ref_facture).FirstOrDefault();
            return View(obj);

        }
    }



@model IEnumerable<STOCK_4_MVC.Models.PS_Details_facture_Liste_Result>

ERROR Select :

@foreach (var item in Model) {
Posted
Updated 25-Nov-20 0:55am
v2

1 solution

As the error clearly states, your view is expecting the model to be IEnumerable<PS_Details_facture_Liste_Result> (a sequence of items) but you are passing in a single item instead.

Either fix your view to match the model passed in by your controller, or fix your controller to pass in the model required by the view.

For example:
public ActionResult Index(int? ref_facture)
{
    var model = db.PS_Details_facture_Liste(ref_facture).ToList();
    return View(model);
}
   
Comments
paradox02 27-Nov-20 5:12am
   
thank you so much

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