Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am Getting error while run my code.i am bit new in mvc3 please help me

index.cshtml

C#
@model IEnumerable<irasoftwares.models.person>
@{
    ViewBag.Title = "Home Page";
    WebGrid grid = new WebGrid();
}


C#
<h2>List Of Person</h2>
@grid.GetHtml(columns:new[]{
grid.Column("ID"),
grid.Column("Name"),
grid.Column("Last Name")
})



model code

C#
namespace IRASoftwares.Models
{
    public class Person
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
    }
}




and controller

C#
public ActionResult Index()
       {
           Person loperson = new Person();
           List<person> lapeaople = new List<person>();

           loperson.id = 101;
           loperson.Name = "Lakhan";
           loperson.Surname = "Aanjana";
           lapeaople.Add(loperson);

           loperson = new Person();
           loperson.id = 102;
           loperson.Name = "Manish";
           loperson.Surname = "Aanjana";
           lapeaople.Add(loperson);

           loperson = new Person();
           loperson.id = 103;
           loperson.Name = "Mahesh";
           loperson.Surname = "Patel";
           lapeaople.Add(loperson);

           loperson = new Person();
           loperson.id = 104;
           loperson.Name = "Nittile";
           loperson.Surname = "Gupta";
           lapeaople.Add(loperson);

           loperson = new Person();
           loperson.id = 105;
           loperson.Name = "Harish";
           loperson.Surname = "Verma";
           lapeaople.Add(loperson);

           loperson = new Person();
           loperson.id = 106;
           loperson.Name = "Lokesh";
           loperson.Surname = "Mor";
           lapeaople.Add(loperson);
           var data = lapeaople;

           return View(data );

       }


but i am getting error please help me
Posted
Updated 8-Oct-13 6:55am
v2

 
Share this answer
 
you have return Ienumarable<loperson>

then it works fine.

and in your view
@model Ienumerable<irasoftwares.models.person>

if not working revert your coment.
 
Share this answer
 

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