就是干不出来 不知道为什么。哪位老哥看一下 真的着急、
逻辑不对,放在哪里从哪里取嘛,ViewData 中取。
新建name je fl tx一个实体类 别用object
视图
@using WebApplication3.Models
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@{
List<TeT> list = ViewBag.list;
}
@foreach (var a in list)
{
<table>
<tr>
<td>@a.FL</td>
<td>@a.Name</td>
<td>@a.JE</td>
<td>@a.TX</td>
</tr>
</table>
}
代码
// GET: Test
public ActionResult Index()
{
List<TeT> list = new List<TeT>();
for (int i = 0; i < 3; i++)
{
TeT a = new TeT();
a.FL = "FL"+i;
a.JE = "JE" + i;
a.Name = "Name" + i;
a.TX = "TX" + i;
list.Add(a);
}
ViewBag.list = list;
return View();
}
实体类
namespace WebApplication3.Models
{
public class TeT
{
public string Name { get; set; }
public string JE { get; set; }
public string FL { get; set; }
public string TX { get; set; }
}
}