ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
AjaxCheckboxList Add data using javascript object
Title:
B
I
{code}
?
having: @(Html.Awe().AjaxCheckboxListFor(x => x.ID).Multiselect(o => o.NoSelectClose()).Url(Url.Action("GetData", "Controller")) 1) i want to pass a data from javascript: var selectionlist={1,2,3}; and display these values in AjaxCheckboxList ? 2) by default select all of them? 3) from client side i want to update the AjaxCheckboxList by passing a different array?
Save Changes
Cancel
warlok
asked at 27 Apr 2016
create a mini demo as explained here: http://aspnetawesome.com/learn/mvc/CommonProblems#Isolate-the-problem try to create or at least draft it, leave some comments, after you upload it I will complete it
at 29 Apr 2016
Omu
Answers
B
I
{code}
?
instead of .Url you can use .DataFunc("jsfunc") to set data and use $('#id').data('api').load() to reload it on demand, in the load method you can pass parameters .load({ params:{ x: 153 } }); or you could also set the last result .data('o').lrs and call render .data('api').render() to select certain items you just call this: $('#id').val("[123,125]").change();
Save Changes
Cancel
Omu
answered at 28 Apr 2016
There is my View and Script: <div id="dynamicControl"></div> <div> <input type="button" id="btnSubmit" value="Submit" /> </div> <script> $("#btnSubmit").click(function (){ $('#dynamicControl').html(@Html.Raw(str)); var selectedItems = ["First", "Second", "Third"]; $('#Mult').val(selectedItems); }); function MultLoad() { var result = []; result.push({ C: "First", K: "First" }); result.push({ C: "Second", K: "Second" }); result.push({ C: "Third", K: "Third" }); return result; } </script>
at 29 Apr 2016
warlok
(This Works in the demo,but not able to select all the items by default)
at 29 Apr 2016
warlok
a button inside a form tag will also submit the form and refresh the page, not sure what are you doing there, anyway that's a different problem; you need to call change event after setting the value or call api render; $('#Mult').val(selectedItems).change();
at 29 Apr 2016
Omu
Missed this in the above code: @{ var str = Json.Encode(Html.Awe().AjaxCheckboxList("Mult").Multiselect(o => o.NoSelectClose()).DataFunc("MultLoad").CssClass("form-control").ToString()); } $('#Mult').val(selectedItems).change(); works fine if there is only one item in selectedItems array but it doesnt work for more than one item. I want to display a AjaxCheckboxList with all of its values selected by default.
at 29 Apr 2016
warlok
selectedItems needs to be a string like "[1,2,3,4]"; so you could call JSON.stringify(["First", "Second", "Third"]);
at 29 Apr 2016
Omu
It Worked Thanks!!
at 29 Apr 2016
warlok
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