MVC网格数据绑定 [英] Mvc Grid Data Bind
问题描述
我使用asp.net mvc3.0剃刀框架,HTML表绑定与ViewBag的帮助数据。我必须证明数据按在DropDownList中选定的选项。
I am using asp.net mvc3.0 razor framework and html Table to bind the data with the help of ViewBag. I have to show Data as per selected option in a dropdownlist.
public ActionResult Index(GetFileName fn)
{
....
ViewBag.Grid1Data =dt;
return View();
}
在第一次,我得到的数据,但是当从下拉列表中另一个选项被选中获得第二个表下一次,不显示表,但我为获取数据。
At first time, I get the data but next time when another option from dropdown is selected to get second table, the table is not displayed, but I m getting the data.
查看包括
下拉菜单
View includes dropdown
<select id="Select2">
<option>Select</option>
<option>abc</option>
<option>des</option>
<option>fgh</option>
<option>next</option>
<option>first</option>
</select>
// Heading for the table
<h2>@ViewBag.Heads</h2>
// Table
<table id="table" cellpadding="10px" cellspacing="0" class="TableSty">
@for (int j = 0; j < ViewBag.Grid1Data.Rows.Count; j++)
{
var color = "";
if (j % 2 == 0)
{ color = "#f2f2f2"; }
else { color = "white"; }
<tr style="background:@color" >
@for (int c = 0; c < @ViewBag.Grid1Data.Columns.Count; c++)
{
<td class="data">@ViewBag.Grid1Data.Rows[j][c].ToString()
</td>
}
</tr>
}
</table>
请帮我解决这个问题。
推荐答案
您选项列表和表未绑定。最好的办法,你用Html.DropDownListFor呈现一个下拉列表,这样,从下拉菜单选择每次,页面刷新,你在viewbag获得更新的数据。
Your option list and table is not bound. Best way, you use Html.DropDownListFor to render a dropdown list, so that on every selection from drop down, the page is refreshed and you get the updated data in viewbag.
或者,你有一个按钮,提交并刷新选择下拉值后手动的页面。
Or, you have a button to submit and refresh the page manually after you select the DropDown value.
这篇关于MVC网格数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!