Reputation: 2188
I'm new to asp.net & I'm trying to making a website where user can sort a table after login. So far sorting is working fine but everytime I click on the link, whol page reloads & data gets sorted. Instead I want only the table gets updated after clicking the link. I'm trying to use AJAX in my view but nothing happened. Here are my codes,
Controller
public ActionResult Login(string sortOrder)
{
if (Session["UserNAME"]!=null)
{
ViewBag.CodeSort = String.IsNullOrEmpty(sortOrder) ? "code_desc" : "";
var sortedOut = new MkistatVsUserLogin { mkistats = dsedb.mkistats.AsQueryable() };
switch (sortOrder)
{
case "code_desc":
sortedOut.mkistats = sortedOut.mkistats.OrderByDescending(s => s.MKISTAT_CODE);
break;
default:
sortedOut.mkistats = sortedOut.mkistats.OrderBy(s => s.MKISTAT_INSTRUMENT_CODE);
break;
}
return View(sortedOut);
}
else
{
return RedirectToAction("Home");
}
}
View
<th>@Html.ActionLink("Codename", "Login", new { sortOrder = ViewBag.CodeSort }, new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "mktTable",
InsertionMode = InsertionMode.Replace
})</th>
How can I solve this problem? Really need this help badly. Tnx.
Upvotes: 0
Views: 940