gpt4 book ai didi

asp.net-mvc-3 - 如何在MVC3中将数据绑定(bind)到Grid?

转载 作者:行者123 更新时间:2023-12-02 02:13:29 25 4
gpt4 key购买 nike

在过去的几天里,我一直在使用 MVC...

我必须在网格中显示一堆数据...这些天我设法在表格中显示它,但我的要求是将它绑定(bind)到 jquery 网格或 Webgrid...

我被困住了,我不知道该怎么做,希望有想法和建议....

Controller

     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>
<%} %>

如果我可以在表格中进行分页,我该怎么做,否则我应该如何在网格中显示他的数据,谁能帮帮我....谁能解释我该怎么做

最佳答案

网络网格示例:

@model IEnumerable<ProjectModel>
@{
var grid = new WebGrid(
source: Model,
rowsPerPage: 4);
}
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "header",
rowStyle: "row",
footerStyle: "footer",
alternatingRowStyle: "altRow",
columns: grid.Columns (
grid.Column("projectName"),
grid.Column("ProjectID")
))

关于asp.net-mvc-3 - 如何在MVC3中将数据绑定(bind)到Grid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11682817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com