0
我想要在一个循环中查看所有列表值的视图,这是我的控制器。有我定制的模型。我也尝试过使用ViewData ['devieList']。但它不适合我。我正在尝试这2天以来,您的帮助将不胜感激。谢谢你提前我想获得值的外观
public ActionResult DeviceList()
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
STGY_SMAPEntities Db = new STGY_SMAPEntities();
var model = new Clients();
DeviceList deviceList = new DeviceList();
model.Items = Db.CLIENT_MASTER.Select(x => new SelectListItem
{
Value = SqlFunctions.StringConvert((double)x.CLIENT_ID),
Text = x.CLIENT_NAME
}).ToList();
foreach (var item in model.Items)
{
var devices = new Devices();
devices.client_Name = model.client_Name = item.Text;
devices.client_ID = model.client_ID = item.Value;
SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM DEVICE_MASTER DM WHERE CLIENT_ID = " + model.client_ID, conn);
SqlDataReader ds = null;
ds = command.ExecuteReader();
if (ds.HasRows)
{
while (ds.Read())
{
devices.device_Count = ds.GetInt32(0);
}
}
deviceList.devicesList.Add(devices);
ds.Close();
}
//IEnumerable<DeviceList> dev = DeviceList;
ViewBag.deviceList = deviceList;
return View(deviceList);// (deviceList);
}
同时我越来越像这样
@{int i = 0;}
@foreach (var x in (List<string>)ViewData["deviceList"])
{
i++;
<tr>
<td>
@*@x.CLIENT_ID*@
<span>@i</span>
</td>
<td>
@x.client_Name
</td>
<td>
@x.device_Count
</td>
<td>
@*<a href="@Url.Action(controllerName: "Home", actionName: "ViewDevices", routeValues: new { Id = @x.CLIENT_ID })"><img src="~/Content/images/copy.png" style="width: 20px" /></a>*@
@*<a href="@Url.Action(controllerName: "Home", actionName: "EditClients", routeValues: new { Id = @x.Clients_Id })" class="btn btn-info" role="button">Edit</a>
<a href="@Url.Action(controllerName: "Home", actionName: "DeleteClients", routeValues: new { Id = @x.Clients_Id })" class="btn btn-info" role="button">Delete</a>*@
</td>
</tr>
}
我能读我的数据?请帮助
thankx模型强烈结合的观点,它的工作原理 –