ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid populate from different action depending on parameter ? [ASP CORE]
Title:
B
I
{code}
?
Is there a way to populate the grid from a api but with a different action from the controller? Like the grid would be loaded by : @Html.Awe().Grid("id") .Url(Url.Action("GetItem","ControllerName")) Then I would like to refresh/update this grid control via an button triggered by an js function. function UpdateGrid() { $("#GridId").Update("GetDifferentItems", "ControllerName") // This should populate the grid with a new set of data }; Is that possible? if so, how?
Save Changes
Cancel
yc
asked at 24 Feb 2021
Answers
B
I
{code}
?
you can call grid api with parameters, and inside the action depending on the parameter return a different model, example: $('#grid1').data('api').load({ params: { flag1: "abc" } }); and now in the `GetItems` action you need a `string flag1` parameter https://www.aspnetawesome.com/learn/mvc/Grid#Api or instead of `.Url` you could use `.DataFunc("getGridData")` and in that js function delegate to an action: function getGridData(sgp) { if(something) return $.get('@Url.Action("GetItems","ControllerName")', sgp); else ... }
Save Changes
Cancel
Omu
answered at 24 Feb 2021
Thanks! that works.
at 24 Feb 2021
yc
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