| I am trying to Hide/Show the 'Edit' link in each row of a given Grid. Basically only few user roles have the access to Modify the information. I wrote a method ActionResult in controller class to check the user access and returning Boolean value. Based on True/False I need to Hide/Show the 'Edit' Links in a grid. The design code is written in MVC CSHTML. Please suggest how it can be achieved. I tried using JQuery but I can hide the Edit column only for the first row of the grid. Below is the code in CSHTML and Jquery. |
CSHTML
<table border="1" cellpadding="0" cellspacing="1" style="width: 90%;"><tr>
<td>
@grid.GetHtml(tableStyle: "webGridMedium",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("BeginDate", "Begin Date", style: "description"),
grid.Column("Status", "Status", style: "description"),
grid.Column("", style: "description10", format: @<a class="edit-status" id="btnEditStatus" rel='nofollow' href="">Edit</a>)
))
</td>
</tr>
</table>
JQuery Code: The parameter data is boolean value I get it from Controller class.
<script>
$(document).ready(function () {
checkAccess();
}
function checkAccess() {
// debugger;
$.ajax({
url: '/Employee/CheckAccess',
type: 'POST',
data: {},
success: function (data) {
if (data == false) {
document.getElementById("btnEditStatus").style.visibility = "hidden";
}
else if (data = true) {
document.getElementById("btnEditStatus").style.visibility = "";
}
},
error: (function (result) {
alert("Failed access! Please contact administrator.");
})
})
}
</script>