ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Two ajax request to grid controller, when using an AjaxDropdown parent filter.
Title:
B
I
{code}
?
In a view, I created a Grid and a AjaxDropdown, using the prodiner example: Chef: @Html.Awe().AjaxDropdown("ChefList").HtmlAttributes(new { Style = "Width:200px;" }) <br /> @(Html.Awe().Grid("Dinner").Columns( new Column { Name = "Id", Width = 55 }, new Column { Name = "Name" }, new Column{Name = "Date"}, new Column{Name = "Chef.FirstName,Chef.LastName", ClientFormat = ".ChefName", Header = "Chef"} ).Parent("ChefList", "nChefId")) And the controller: public class DinnerGridController : Controller { public ActionResult GetItems(GridParams g, int? nChefId) { // null validation, return empty model if (nChefId == null) return Json(new { }); var query = Db.Dinners.Where(o => o.Chef.Id == nChefId).AsQueryable(); return Json( new GridModelBuilder<Dinner>(query, g) { Key = "Id", // needed when using Entity Framework Map = o => new { o.Id, o.Name, o.Date, ChefName = o.Chef.FirstName + " " + o.Chef.LastName } }.Build()); } } When I request the page in Firefox, I get two consecutive Ajax Request to the GridController, the first one with the ‘nChefId’ equals to null, and the second one with the correct Dropdown value. I put a null validation in the GridController, but I get a javascript error in AwesomeMvc.js _TypeError: t is undefined http://localhost:43993/Scripts/AwesomeMvc.js Line 1 function(n,t){ei(t)&&ki++});sr.empty();t.Groups&&(ct=0);ct&&sr.append(li(t,0,0,0..._ This behavior started when I updated to version 4.7.3., in later versions the grid controller is called only once with the correct dropdown value.
Save Changes
Cancel
Intersel
asked at 30 Sep 2015
in the grid GetItems action you should always return the result of GridModelBuilder.Build even if the items is an empty collection, to get just one request give the AjaxDropdown a value (.Value)
at 30 Sep 2015
Omu
Thanks for your help!
at 30 Sep 2015
Intersel
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK