أماني مفيد

أماني مفيد

  • NA
  • 142
  • 15.8k

error in return view MVC

Sep 29 2020 6:31 AM
i have this controller :
  1. public ActionResult search(int? page, string search , string KEYWORD_NAME)  
  2. {  
  3. if (search == null)  
  4. {  
  5. Bindkeyword();  
  6. return View();  
  7. }  
  8. else  
  9. {  
  10. KEYWORD_NAME = Request.QueryString["Contant.KEYWORD_NAME"];  
  11. Bindkeyword();  
  12. DataSet dst = new DataSet();  
  13. dst.Tables.Add(op.search(search, KEYWORD_NAME));  
  14. List<ContantViewModel> seaech = new List<ContantViewModel>();  
  15. foreach (DataRow dr in dst.Tables[0].Rows)  
  16. {  
  17. ContantViewModel u = new ContantViewModel();  
  18. u.articalname = dr["ARTICAL_NAME"].ToString();  
  19. u.articalbody = dr["ARTICALBODY"].ToString();  
  20. u.userName = dr["IUSER"].ToString();  
  21. u.articlid = dr["ARTICL_ID"].ToString();  
  22. seaech.Add(u);  
  23. }  
  24. if (seaech.Count > 0)  
  25. {  
  26. op.addsearch(search, KEYWORD_NAME);  
  27. return View(seaech.ToPagedList(page ?? 1, 10));  
  28. }  
  29. else  
  30. {  
  31. ContantViewModel u = new ContantViewModel();  
  32. u.s = "there is no data ";  
  33. u.s1 = "e.jpg";  
  34. seaech.Add(u);  
  35. return View(seaech.ToPagedList(page ?? 1, 10));  
  36. }  
  37. }  
  38. }  
 
and this is the view
 
i use this model :@model Wiki_Reach_Site.Models.ContantViewModel
 
i have error in the line in BOLD
 
this is the error
 
System.InvalidOperationException: The model item passed into the dictionary is of type 'PagedList.PagedList`1[Wiki_Reach_Site.Models.ContantViewModel]', but this dictionary requires a model item of type 'Wiki_Reach_Site.Models.ContantViewModel'.
 
how i can fix it ?

Answers (9)