【发布时间】:2014-01-04 22:19:22
【问题描述】:
我是 ASP.NET MVC3 的新手,并且拼命尝试让一些简单的工作。我觉得我正在尝试做一些非常简单的事情。但是,我无法让基本网格正常工作。我在 Visual Studio 中使用默认设置,这就是我所做的:
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 打印任何内容。我期待两行。相反,我一无所获。我做错了什么?
【问题讨论】:
标签: asp.net-mvc-3