Ajax.ActionLink() Not Redirecting To ActionResult With Ajax Attribute
Given that I have this code in my .cshtml page using Ajax.ActionLink() that calls a controller method using Ajax request:
And the controller method called by the Ajax ActionLink is decorated with Ajax attribute.
Normally, the request would push through. If does not proceed, maybe you have not added the Microsoft JQuery Unobtrusive Ajax to your project. Downloading and installing
the said package(Microsoft JQuery Unobtrusive Ajax) via NuGet might fix the problem.
@Ajax.ActionLink("Select", "TaskListing", new { id = item.TaskID }, new AjaxOptions(){ HttpMethod = "GET", UpdateTargetId = "taskListing", InsertionMode = InsertionMode.Replace })
[HttpGet] [AjaxOnly(true)] [ActionName("TaskListing")] public ActionResult TaskListing_Ajax(int id = -1) { var projects = projRep.GetAllProjects(); var model = new TaskAndTaskViewModel(); model.Task = te.Tasks.FirstOrDefault(t => t.TaskID == id); model.SelectList = from p in projRep.GetAllProjects() select new SelectListItem { Selected = (p.ProjectID == Convert.ToInt32(model.Task.ProjectID)), Text = p.ProjectName.ToString(), Value = p.ProjectID.ToString() }; return PartialView("TaskForm", model); }
Comments
Post a Comment