You should try something like this in the
controller
public JsonResult GetdynamicMenu()
{
string dynamicMenu = "<nav><ul id=\"menu\">";
dynamicMenu += "<li>" + GetActionLink("Employee","GetEmployee","Employee") + "</li>";
dynamicMenu += "<li>" + GetActionLink("Absenteeism","GetAbsents","Absenteeism") + "</li>";
dynamicMenu += "<li>" + GetActionLink("Order", "GetOrders", "Order") + "</li>";
dynamicMenu += "<li>" + GetActionLink("Order", "GetOrders", "Order") + "</li>";
dynamicMenu += "<li>" + GetActionLink("Report", "GenerateReport", "Report") + "</li>";
dynamicMenu += "<li>" + GetActionLink("Evaluation", "GenerateEvaluation", "Evaluation") + "</li>";
dynamicMenu += "</ul></nav>";
return Json(dynamicMenu, JsonRequestBehavior.AllowGet);
}
private string GetActionLink(string controller, string action, string name)
{
string link = Url.Action("GetEmployee", "Employee");
string actionLink = "<a href='" + link + "'>" + name + "</a>";
return actionLink;
}
Since you are hardcoding the ActionLink helper (
@Html.ActionLink("Employee","Employee","GetEmployee")
), during the runtime when building the View, it will will execute the
ActionLink
Method and
generates the anchor link dynamically
. so you could able to view the links.
but if you are getting the values as a string in Ajax call, these Links will be considered as
raw text only. because MVC wont compile those ActionLink in ajax calls in the View,
So you can use the above code to generate the anchor links from controller itself.