javascript - Additional parameter for index page sort collection -
i have page renders question objects set of <div>
's. (i use pagination don't think it's of significance particular problem).
i give user opportunity choose order in items displayed (aka order of underlying question list.
i figured using <select>
list simple way, doesn't seem working. i'm struggling calling action controller javascript. have far:
my html:
<select id="sort-select" style="margin-bottom: 10px"> @foreach (sortingtype value in enum.getvalues(typeof (sortingtype)).cast<sortingtype>()) { <option value="@((byte)value)">@(value.tostring())</option> } </select>
(sortingtype enum conatining 3 constants.)
my javascript:
function addsort() { var select = document.getelementbyid('sort-select'); select.onchange = function(event) { var selected = select.options[select.selectedindex].value; var url = encodeuri("@url.action("index", new {topicid = viewbag.topicid, sort = 0})"); url.replace('&', '&'); url.replace(0, selected); window.location.href = url; } }
this of course gets called in document.ready.
the problem that, when js runs, forms ampersands (&) escaped equivalent (&). of course not working because parameters actions of controller separated pure ampersands.
i link when try change selection:
http://localhost:41084/question?topicid=-1&sort=0
anyone idea on how can solve this? i'm not sure how can call actions javascript in proper manner, , don't know if javascript way go here.
found solution had url = url.replace(...)
instead of url.replace(...)
!
my javascript looks this:
function addsort() { var select = document.getelementbyid('sort-select'); select.onchange = function(event) { var selected = select.options[select.selectedindex].value; var url = encodeuri("@url.action("index", "question", new {topicid = viewbag.topicid, sort = 0})"); url = url.replace('&', '&'); url = url.replace(0, selected); window.location.href = url; } }
Comments
Post a Comment