我有以下问题,我想刷新一个asp.mvc控件。
<table>
<tr>
<td>Rolle</td>
<td>
<div>
@Html.Telerik().ComboBox().Name("DdlRoleAuthority").SelectedIndex(-1).BindTo(Model.RoleList)
</div>
</td>
</tr>
<tr>
<td valign="top">Programme</td>
<td>
<div style="width:240px;height:160px;color:White;">
@Html.CheckBoxListFor(model => model.AuthorityRoles, Model.AuthorityRoleList)
</div>
</td>
</tr>
</table>
我有一个Telerik Combobox,当它被更改时,我想刷新Checkbox列表。 javascript是
$(document).ready(function () {
alert('a1');
$('#DdlRoleAuthority').bind('valueChange', function(e) {
onRoleAuthorityChange(e.value);
});
}
function onRoleAuthorityChange(e) {
alert('0');
var userId =document.getElementById('CurrentID').value;
$.ajax({
url: '@Url.Action("RoleListIndexChanged", "User")',
type: 'get',
dataType: 'html',
data: {roleId: e, userId : userId},
success: function(data)
{
$('#AuthorityRoles').dataBind(result);
}
});
alert('1');
}
行动是
public ActionResult RoleListIndexChanged(int? roleId, int? userId)
{
UserSettingsViewModel result = CreateSettingsViewModel(userId.Value, roleId);
return PartialView(result.AuthorityRoleList);
}
我该怎么办,以便刷新CheckboxList?
复选框列表是
public static MvcHtmlString CheckBoxListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty[]>> expression, MultiSelectList multiSelectList, object htmlAttributes = null)
{
MemberExpression body = expression.Body as MemberExpression;
string propertyName = body.Member.Name;
TProperty[] list = expression.Compile().Invoke(htmlHelper.ViewData.Model);
List<string> selectedValues = new List<string>();
if (list != null)
{
selectedValues = new List<TProperty>(list).ConvertAll<string>(delegate(TProperty i) { return i.ToString(); });
}
TagBuilder divTag = new TagBuilder("div");
divTag.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
foreach (SelectListItem item in multiSelectList)
{
divTag.InnerHtml += string.Format(
"<div><input type=\"checkbox\" name=\"{0}\" id=\"{0}_{1}\" " +
"value=\"{1}\" {2} /><label for=\"{0}_{1}\">{3}</label></div>",
propertyName,
item.Value,
selectedValues.Contains(item.Value) ? "checked=\"checked\"" : string.Empty,
item.Text);
}
return MvcHtmlString.Create(divTag.ToString());
}