在过去的几天里,我一直在使用 MVC ......
我必须在网格中显示一堆数据......这些天我设法在表格中显示它,但我的要求是将它绑定到 jquery 网格或 Webgrid ......
我被困住了,我不知道该怎么做,期待想法和建议....
控制器
public ActionResult Index()
{
var bugList = GetList();
return View(bugList);
}
public List<ProjectModel> GetList()
{
var modelList = new List<ProjectModel>();
using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
{
conn.Open();
SqlCommand dCmd = new SqlCommand("Select * from Projects", conn);
SqlDataAdapter da = new SqlDataAdapter(dCmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
var model = new ProjectModel();
model.ID = Convert.ToInt16(ds.Tables[0].Rows[i]["ProjectID"]);
model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString();
model.Description = ds.Tables[0].Rows[i]["Description"].ToString();
model.status = ds.Tables[0].Rows[i]["Status"].ToString();
modelList.Add(model);
}
}
return modelList;
}
查看 (ASPX)
<table>
<thead align="center">
<tr class="BoldCenterAlignHeaderStyle">
<th>
ProjectName
</th>
<th>
Status
</th>
<th align="center">
Edit
</th>
</tr>
</thead>
<% foreach (var item in Model) { %>
<tr>
<td>
<%:Html.LabelForModel(item.projectName) %>
</td>
<td>
<%:Html.LabelForModel(item.status) %>
</td>
<td align="center">
<a href="<%:Url.Action("Edit",new{id=item.ID}) %>" class="Edit"><img src="../../Content/edit.gif" height="8px"/></a>
<%--<%:Html.ActionLink("Edit", "Edit", new { id = item.ID })%> --%>
<%-- <a href="<%:Url.Action("Delete",new{id=item.ID}) %>" class="Delete"><img src="../../Content/delete.gif" height="8px" /></a>--%>
</td>
</tr>
<%} %>
如果我可以在表格中进行分页,我该怎么做,否则我应该如何在网格中显示他的数据,谁能帮助我......谁能解释一下我该怎么做