lundi 13 février 2017

"The model item passed into the dictionary is of type '" [duplicate]

i need show all category in view . i used this code for show all :

Category = Tabel name of Database

public List<Category> GetAllCategory()
    {
        return _repository.GetAll();
    }

/****************************************/

public ActionResult ListCategory()
    {
        return View(_CategoryService.GetAllCategory());
    }

/*****************************************/

i create model CategoryModel .

 public class CategoryModel 
{
    [Display(Name ="کد دسته")]
    public int CatID { get; set; }
    [Display(Name = " نام دسته")]
    public string CategoryName { get; set; }
    [Display(Name = " سر دسته")]
    public int ParentID { get; set; }
}

/**********************************/

and in view i use this :

@model IEnumerable<Amene.Models.CategoryModel>

but it show me this error :

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[DA.Data.DB.Category]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[Amene.Models.CategoryModel]'.

o know i must user table name in view Category but i need use CategoryModel .

how can i do this ?

Aucun commentaire:

Enregistrer un commentaire