Click here to Skip to main content
15,915,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The page I'm working on binds html elements to a related model by adding this at the time of the cshtml page:

@model TLDReporter.Models.PlatypusCriteriaModel

...and then, in the html, uses the elements' name attribute to bind to model members, such as "BeginDate" like so:

<input id="BeginDate" name="BeginDate" />

However, I need to store a list of items in one of the model members, which is a generic list of string, and the widget I'm presenting the user to select the criteria is a jQuery plugin that is hosted by a jQuery UI accordion widget. So, I can't just bind to it with a name property, I don't think. IOW, I don't think adding:

name="ListDepts"

inside the #depts div will help me out.

Here's the code which hopefully elucidates the milieu:

HTML

HTML
<div id="accordion">
        <h3 id="deptHeader">Departments (selected: <span>all</span>)</h3>
        <div id="depts" class="checkboxGroups5Col">
        </div>
        <h3 id="sitesHeader">Sites (selected: <span>all</span>)</h3>
        <div id="sites" class="checkboxGroups3Col">
       </div>
    </div>


jQuery

JavaScript
var deptsArray = [];
    for (var i = 2; i < 100; i++) {
        deptsArray.push(i);
    }

        $('#accordion').accordion();
        $('#depts').appendAllCheck().appendCheckboxes('deptsCheckboxList', deptsArray, {
             checked: true
        });


(the "appendAllCheck()" and "appendCheckboxes()" above are in a custom jQuery plugin).

What I really need to bind to the model member ("ListDepts") is something like deptsListCSV here:

JavaScript
deptsList = $('#depts').checkedBoxes();
    deptsListCSV = deptsList.join(", ");


Does anybody have experience with a scenario like this that is willing to clue me in?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900