Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[WebApplication2.personaldetail]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[WebApplication2.Models.personaldetails]'.


What I have tried:

@model IEnumerable<webapplication2.models.personaldetails>
Posted
Updated 23-May-16 21:13pm
Comments
Karthik_Mahalingam 24-May-16 2:45am    
post the code.

You should use the model type as the Type returning from the Action.

C#
@model IEnumerable< WebApplication2.Models.personaldetails>

C#
@model List< WebApplication2.Models.personaldetails>


or

C#
var data = obj.personaldetails.ToList();

C#
var data = obj.personaldetails.AsEnumerable();
 
Share this answer
 
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication2.Controllers;


namespace WebApplication2.Controllers
{
public class demoController : Controller
{
detailsEntities1 obj = new detailsEntities1();

public ActionResult Index()
{
return View();
}
public ActionResult webgrid()
{
var data = obj.personaldetails.ToList();
return View(data);

}


}
-----------------------------------------------------
@model IEnumerable< WebApplication2.Models.personaldetails>

@{
ViewBag.Title = "webgrid";
WebGrid grid = new WebGrid(Model,canSort:false,defaultSort:"firstname",rowsPerPage:3,
columnNames:new[]{"firstname","lastname"});
}
@grid.GetHtml(columns:grid.Columns(grid.Column("firstname",header:"firstname"),
grid.Column("lastname","lastname"),
grid.Column("id","id"),
grid.Column("active","active")))

webgrid


-----------------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace WebApplication2.Models
{
    public class  personaldetails
    {
        public string id { set; get; }
        public string firstname { set; get; }
        public string lastname { set; get; }
        public string active { set; get; }
    }
}
 
Share this answer
 
Comments
Karthik_Mahalingam 24-May-16 3:08am    
Always use  Reply  button, to post Comments/query to the user, else the User wont get notified.
Use Improve question to update the question.
Dont use Solution widget to post comments, Please delete it.

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