我是ASP.NET MVC3的新手,并拼命地尝试着简单地工作。我觉得我正在尝试做一些非常简单的事情。但是,我无法获得一个基本的网格。我使用Visual Studio中的默认设置,这里是我做了什么:在MVC3中使用WebGrid
HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
List<Person> test = new List<Person>();
test.Add(new Person("John", "Smith"));
test.Add(new Person("Bill", "Torr"));
return View(test);
}
public ActionResult About()
{
return View();
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Person(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
}
}
Index.cshtml @ { ViewBag.Title =“主页”; }
<h2>@ViewBag.Message</h2>
<p>
@{
var grid = new WebGrid(@Model);
grid.GetHtml();
}
</p>
奇怪的是,没有被打印出来了的WebGrid。我期待着两排。相反,我什么也没得到。我究竟做错了什么?
但我不能在.cshtml文件中引用的人。如果我尝试@model IEnumerable
@Villager,当然你可以参考它。只需提供完整的命名空间'@model IEnumerable'。甚至更好,这个命名空间添加到你的'〜/查看/ web.config'文件的''部分,这样你就不必在所有的意见都做一遍。 –
没关系。得到它了。谢谢。 – Villager