更新时间:2022-11-30 16:22:20
它为您提供错误,因为您没有将模型分配给网格,请检查以下链接:
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor .aspx [ ^ ]
如何使用razor在asp.net mvc 4中使用网格引擎 [ ^ ]
你有返回Ienumarable< loperson>
然后它工作正常。
和你的v iew
@model Ienumerable< irasoftwares.models.person>
如果不能恢复你的冥想。
Hello,
I am Getting error while run my code.i am bit new in mvc3 please help me
index.cshtml
@model IEnumerable<irasoftwares.models.person>
@{
ViewBag.Title = "Home Page";
WebGrid grid = new WebGrid();
}
<h2>List Of Person</h2>
@grid.GetHtml(columns:new[]{
grid.Column("ID"),
grid.Column("Name"),
grid.Column("Last Name")
})
model code
namespace IRASoftwares.Models
{
public class Person
{
public int id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
}
and controller
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
It gives you error as you didn't assign model to grid, check these links:
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx[^]
How to use grids in asp.net mvc 4 with razor engine[^]
you have return Ienumarable<loperson>
then it works fine.
and in your view
@model Ienumerable<irasoftwares.models.person>
if not working revert your coment.