1
任何人都可以看到为什么这个简单的测试网站打印出一个空表(在HTML中,一个表正在创建2行(tr),但没有单元格(TD)正在生产)。WebGrid打印出一张空表
或者是如何去调试它
DebugController.cs的最佳途径......
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
namespace myproject.Controllers
{
public class type1
{
public String ipAddress;
public String connectionId;
}
public ActionResult Debug2(string arg1)
{
List<dynamic> obj1 = new List<dynamic>();
obj1.Add(new type1 {ipAddress="192.168.1.1", connectionId="123"});
obj1.Add(new type1 {ipAddress="192.168.1.2", connectionId="345"});
ViewBag.obj1 = obj1;
return View();
}
}
}
而且Debug2.cshtml ....
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="~/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.signalR-1.1.3.js"></script>
<script type="text/javascript" src="~/signalr/hubs"></script>
@{
var grid = new WebGrid(ViewBag.obj1);
}
</head>
<body>
<div>
@grid.GetHtml()
</div>
</body>
</html>
非常感谢,但现在它抱怨说“类型或名称空间名称”类型1'找不到“我在.cshtml的顶部添加了@using myProjectNamespace,但这并没有帮助 – spiderplant0
从你所显示的'Type1'是在myproject.Controllers命名空间中声明的。另外请注意,我使用了'Type1'而不是'Type1',它在语义上更加正确的在C#中的类的名称。确保你没有错别字。 –
确定将其更改为:'@model IList',它都可以工作!非常感谢。 –
spiderplant0