能否请您给我一个关于如何在MVC / Razor / Javascript中执行此操作的想法:
我正在从模型中添加材料类型复选框。当用户选中复选框时,我想更改“属性过滤器”下内容的内容。最终,将存在一个按钮,用于根据所选的材料类型和属性过滤器以某种方式“填充” Telerik网格的材料列表。
但是现在,我该如何将属性列表(我将从模型中拉出)添加到<td>
标签中?
用WPF叹气这太容易了...
这是我的cshtml:
@model Procurement.Models.Material.MaterialType
@using (@Html.BeginForm("GetFilteredMaterials", "MaterialsList", FormMethod.Get))
{
<table>
<tr>
<th width="40%">
@Html.Label("Material Type: ", new { style="font-weight:bold;" } )
</th>
<th><b>@Html.Label("Property Filters:", new { style = "font-weight:bold;" }) </b></th>
</tr>
<tr>
<td>
@*Material Types list*@
@if (Model != null)
{
for(int i=0; i < Model.MaterialTypeList.Count; i++)
{
@Html.CheckBox(Model.MaterialTypeList[i].Name, new { @onclick="CallChangefunc()" })
@Html.Label(Model.MaterialTypeList[i].Name)<br />
}
}
</td>
<td>
@*Property list*@
</td>
</tr>
</table>
}
<script>
function CallChangefunc(val) {
alert("i am here ", val);
//alert(obj.options[obj.selectedIndex].text);
//window.location.href = "/Materials/MyMethod/" + val;
}
</script>
更新
除了参数未进入Controller函数调用之外,此方法均有效:
更新的JQuery:
<script>
function CallChangefunc(value) {
//alert("i am here " + value);
window.location = '@Url.Action("GetFilteredMaterials", "MaterialsList")' + '/' + value;
}
</script>
这是控制器端功能:
public void GetFilteredMaterials(string value)
{
int x = 0;
}
在“ int x = 0;”行上设置断点代码中断。但是值是空的。有人可以帮忙吗?