I am working on an MVC3 application. I have some logic in my view that I want to move to my controller. It dynamically displays an ActionLink depending on certain aspects of the model. The linkText and the actionName parameters for Html.ActionLink are the only thing that can differ. I added a method to my controller that would return a JsonResult with strings for linkText and actionName:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetActionButton(int id)
{
string action = null;
string text = null;
// Snipped stuff that sets action and text
return Json(new
{
buttonAction = action,
buttonText = text
});
}
Where could I call this method to create the link using the results?
For link generation from controller look at UrlHelper Methods, it’s better to use
Actionfor receiving normal url. On client with jquery you can create link like: