Hi,
I have one table with fields
EId Id ControllerName Url
1 1 report /report/Index/
2 2 report1 /eport1/Index/
assume session will be 1
then how to pass this id to controller
public JsonResult getAll(int Id)
{
db.Configuration.ProxyCreationEnabled = false;
using (ReportEntities dataContext = new ReportEntities())
{
var employeeList = (from E in dataContext.MenuSelection1
where E.EId==Id
orderby E.Id
select new
{
E.Id,
E.ControllerName,
E.Url
}).ToList();
var JsonResult = Json(employeeList, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var Id1 = 1;//var Id1=@Session["EId"]
$.ajax({
type: "POST",
url: "/menuselection/getAll/",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Id: Id1}),
dataType: "json",
success: function (r) {
var ul = $('#unordered');
$.each(r, function (i, item) {
ul.append("<li><a href='" + item.Url + "'>" + item.ControllerName + "</a></li>");
});
}
});
});
</script>