This is a migrated thread and some comments may be shown as answers.

issues with populating a grid only after user input

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 13 Oct 2012, 12:38 AM
I have a pretty basic grid that is not populated on load.  It requires users to enter search criteria first, which then searches the database and populates the grid.  Below is the grid code

Html.Kendo().Grid<ArrayOfSearchResultObjectSearchResultObject>(Model.Results)
.Name("srchGrd")
.Columns(columns =>
{
    columns.Bound(o => o.Chemical).ClientTemplate("<a title='#=Chemical#' href='" + Url.Action("", "ChemBioSearch", new { area = "Tools" }, Request.Url.Scheme) + "/GetDetail?ChemName=#=Chemical#&DetailID=#=ID#&DetailSource=#=SearchSource#&id=" + Model.ProjectGUID.ToString() + "' >" +
    "#=Chemical# </a>"
    ).Title("Chemical");
    columns.Bound(o => o.CasNumber).Title("CAS #");
    columns.Bound(o => o.UnNumber).Title("UN ID #");
    columns.Bound(o => o.FriendlySourceName).Title("Data Source");
})
        .DataSource(ds =>
        {
            ds.Ajax().ServerOperation(false).Read(read => read.Action("_GetSearchResults", "ChemBioSearch", new { area = "Tools" }));
        }
                    )
.Scrollable(scrolling => scrolling.Enabled(false))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(false))
.Render();
which used to work great but broke ever since i upgraded to the Kendo 924 version (and same problem since the 1002 as well) it doesn't work like it used to. 

Basically i have 2 controller methods.  The first (SearchChemBio) gets called when the user enters the search data and hits enter.  data gets sent no problem and send a partialresult (which contains the grid).  I have the ajax call in there in order to handle sorting/filtering/paging. 

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult _GetSearchResults([DataSourceRequest] DataSourceRequest request,ChemBioSearchModel mdl)
{
    if ((mdl != null) && (mdl.IsValid))
    {
        ArrayOfSearchResultObject rslt = SearchGlobal(mdl);
        if ((rslt != null) && (rslt.Items.Length > 0))
        {
            foreach (ArrayOfSearchResultObjectSearchResultObject arr in rslt.Items)
            {
                mdl.Results.Add(arr);
            }
        }
        return Json(mdl.Results.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }
    return Json(new List<ArrayOfSearchResultObjectSearchResultObject>().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
 
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SearchChemBio(ChemBioSearchModel mdl)
{
    if (mdl != null)
    {
        if (ModelState.IsValid)
        {
            ArrayOfSearchResultObject rslt = SearchGlobal(mdl);
            if ((rslt != null) && (rslt.Items !=null) && (rslt.Items.Length > 0))
            {
                foreach (ArrayOfSearchResultObjectSearchResultObject arr in rslt.Items)
                {
                    mdl.Results.Add(arr);
                }
            }
            return PartialView("SearchResults", mdl);
        }
        else
        {
            return View(mdl);
        }
    }
    throw new ArgumentException("No Model found for Chem Bio Search");
}
unfortunately now, the model in the Ajax call (_GetSearchResults) is always blank now (it didn't used to be before the update).  Is there something i'm missing?  I feel like i'm doing double work here, but can't figure out how to marry both calls.

1 Answer, 1 is accepted

Sort by
0
Phil
Top achievements
Rank 1
answered on 15 Oct 2012, 06:22 PM
issue ended up me using AllowGet.  Had to change that to DenyGet and it worked fine.
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Phil
Top achievements
Rank 1
Share this question
or