以下 EditorTemplate 无法正常工作;
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.Models.BusinessUnitSelected>" %>
<tr>
<td><%: Model.BusinessUnit.BusinessUnitName %></td>
<td><%: Html.CheckBoxFor(model => model.Selected,
new { onclick = "SaveSelection(" + Model.EmployeeId + ", " + Model.BusinessUnit.BusinessUnitId + ", " + Convert.ToInt32(Model.Selected) + ", " + this.ClientID + ")" }) %>
</td>
</tr>
我想获取复选框的 ID,而 this.ClientID 无法做到这一点。此 EditorTemplate 在表中形成行网格。当一个人点击复选框时,会执行 SaveSelection javascript;
function SaveSelection(employeeId, businessUnitId, selectedFlag, elementId) {
//var tempFlag = selectedFlag === "0";
var element = document.getElementById(elementId);
if (selectedFlag === null) {
selectedFlag = true;
} else {
selectedFlag = !selectedFlag;
}
var url = '<%: Url.Action("AddBusinessUnitForEmployee", "DataService")%>';
dataService.saveSelection(employeeId, businessUnitId, selectedFlag, elementId, SavedSetting, url);
}
SavedSetting = function(data) {
$('#' + data.ElementId).after('<span class="error">' + data.Message + '</span>');
};
我想要的是在服务器调用后在复选框旁边显示一条消息。那么我该怎么做呢?Upticks 将获得有关如何改进此代码的建议。