C# ur模型(模型类型视图列表)在表格中显示结果: @model sample.viewList <table> @foreach (var item in Model) { <tr> <td>@item.field1</td> </tr> } </table> @model sample.viewList @foreach(模型中的var项目) { @项目1.1 }
备选方案 要在弹出窗口中显示,请将列表放入ViewBag,如下所示:C# ur模型(模型类型视图列表)在表格中显示结果: @model sample.viewList <table> @foreach (var item in Model) { <tr> <td>@item.field1</td> </tr> } </table> @model sample.viewList @foreach(模型中的var项目) { @项目1.1 },c#,asp.net,asp.net-mvc-3,C#,Asp.net,Asp.net Mvc 3,备选方案 要在弹出窗口中显示,请将列表放入ViewBag,如下所示: List<viewList> theList = new List<viewList>(); //Populate dbread here... while (dbread.Read()) { viewList listData = new viewList(); listData.field1 = (dataType)dbread[0]; theList.Add(l
List<viewList> theList = new List<viewList>();
//Populate dbread here...
while (dbread.Read())
{
viewList listData = new viewList();
listData.field1 = (dataType)dbread[0];
theList.Add(listData);
}
ViewBag.Items = theList;
List theList=新列表();
//在这里填充dbread。。。
while(dbread.Read())
{
viewList listData=新建viewList();
listData.field1=(数据类型)dbread[0];
添加(列表数据);
}
ViewBag.Items=列表;
那么在你看来,
<script type="text/javascript">
$(function() {
var array = @Html.Raw(Json.Encode(ViewBag.Items));
//Construct your table using the array here...
alert(theConstructedTable);
});
</script>
$(函数(){
var数组=@Html.Raw(Json.Encode(ViewBag.Items));
//使用此处的数组构造表。。。
警报(构造表);
});
此页面似乎不是MVC。MVC不使用脚本运行
或页面加载
或响应。写入
。您可能正在编写一个MVC应用程序,但您的问题没有MVC方面。请更正,这不是MVC,我只是在用这个页面测试DB连接。我把这段代码贴在这里是想告诉大家我在做什么,这在MVC应用程序中不会出现。这个页面看起来不是MVC。MVC不使用脚本运行
或页面加载
或响应。写入
。您可能正在编写一个MVC应用程序,但您的问题没有MVC方面。请更正,这不是MVC,我只是在用这个页面测试DB连接。我将这段代码粘贴在这里是为了让大家了解我正在尝试做什么,这在MVC应用程序中不会出现。谢谢,这很好,但我认为我没有正确地说明我的问题…..我正在我的新帖子中添加更多细节,下面是我的原始帖子,根据您的编辑添加了更多细节,在将另一个查询传递到视图之前,您应该在控制器中执行该查询。谢谢,这很好,但我认为我没有正确地说明我的问题…..我正在我的新帖子中添加更多详细信息,如下所示。根据您的编辑,我在原始帖子中添加了附加详细信息,您应该在控制器中执行另一个查询,然后再将其传递给视图。谢谢,我可以使用………将参数传递给控制器@Html.ActionLink(ShowColumns.Column_Name,“BrowseQueries”,new{ColumnIs=ShowColumns.Column_Name})………最后一个悬而未决的部分或难题是我如何在另一个视图中捕获此查询并使其在单独的db服务器上运行感谢我能够使用………将参数传递给控制器@ActionLink(ShowColumns.Column_Name,“browsequenceries”,new{ColumnIs=ShowColumns.Column_Name})……最后一个悬而未决的部分或难题是我如何在另一个视图中捕获此查询并使其在单独的db服务器上运行
namespace sample {
class viewList
{
public string field1 {get;set;}
...
}
}
List<viewList> theList = new List<viewList>();
//Populate dbread here...
while (dbread.Read())
{
viewList listData = new viewList();
listData.field1 = (dataType)dbread[0]; //Convert to your data type
theList.Add(listData);
}
return view(theList);
@model sample.viewList
<table>
@foreach (var item in Model)
{
<tr>
<td>@item.field1</td>
</tr>
}
</table>
List<viewList> theList = new List<viewList>();
//Populate dbread here...
while (dbread.Read())
{
viewList listData = new viewList();
listData.field1 = (dataType)dbread[0];
theList.Add(listData);
}
ViewBag.Items = theList;
<script type="text/javascript">
$(function() {
var array = @Html.Raw(Json.Encode(ViewBag.Items));
//Construct your table using the array here...
alert(theConstructedTable);
});
</script>