This question is locked. New answers and comments are not allowed.
I noticed something strange in terms of the way the grid sorting works. I have a textbox on a view. It is a filter. The user types in a value and clicks submit. The controller has 2 methods, one for the get and one for the post. Code below. All works fine, the grid displays the filtered results. Pretty standard. However, if I click on a column to sort it, the entire grid disappears. I traced the code and noticed that when I click on a column to sort it, the GET action method is being called rather than the POST action method. It seems to me that clicking on a column does a postback and thus the POST action method should be called not the GET action method. Since the GET action method is being called, it returns a view with no data and hence the grid disappears. Is this by design or am I missing something?
Many Thanks,
Ed
public ActionResult Filter()
{
return View();
}
[HttpPost]
public ActionResult Filter(FormCollection collection)
{
using (GroupBuyDataContext db = new GroupBuyDataContext())
{
IEnumerable<Deal> results = null;
if (!string.IsNullOrEmpty(collection["all"]))
results = db.Manager.Deal.GetAll();
else if (!string.IsNullOrEmpty(collection["filter"]))
results = db.Manager.Deal.GetByTitle(collection["name"]);
ViewData["contains"] = collection["name"];
if (results != null)
return View(results.ToList());
else
return View();
}
}
Many Thanks,
Ed
public ActionResult Filter()
{
return View();
}
[HttpPost]
public ActionResult Filter(FormCollection collection)
{
using (GroupBuyDataContext db = new GroupBuyDataContext())
{
IEnumerable<Deal> results = null;
if (!string.IsNullOrEmpty(collection["all"]))
results = db.Manager.Deal.GetAll();
else if (!string.IsNullOrEmpty(collection["filter"]))
results = db.Manager.Deal.GetByTitle(collection["name"]);
ViewData["contains"] = collection["name"];
if (results != null)
return View(results.ToList());
else
return View();
}
}