How to Create Dropdown List with Checkboxes for each item present in the dropdown in mvc3 Razor

Posted by ramuvalmiki07-22001 under ASP.NET on 6/26/2013 | Points: 10 | Views : 1643 | Status : [Member] | Replies : 0
Hii to all,
I have a requirement that i need to place two dropdown lists.In First Dropdown i need to display Employee Ids from database,when user selects any Id,the respective EmployeeIds Name should display in another second dropdown.I have done this succesfully, but here what my actuall requirement is i need to show my first dropdown with Checkboxes i.e for each EmployeeId i need to show one Checkbox to the left of the Id,then user can select multiple ids in the same order i need to show checked ids Names in Second Dropdown, i have tried by googling and downloaded dropdownchecklist plugin,but i was unable to reach my requirement.Iam using MVC3 Razor.

Here is my View Code:-

<pre lang="sql">&lt;fieldset&gt;
EmployeeIds&lt;br /&gt;
@Html.DropDownListFor(m =&gt; m.selectedEmpid, new SelectList(Model.getAlldeptNos), &quot;Select Empid&quot;, new { id = &quot;getSelectedId&quot; })
@Html.DropDownListFor(m =&gt; m.selectedEmpid, new SelectList(Model.getEname), new { id = &quot;displayEname&quot; })&lt;br /&gt;
&lt;script type="text/javascript">
<pre lang="xml">$(function () {
$(&#39;#getSelectedId&#39;).change(function () {
var selectedEmpIdValue = $(this).val();
url: &#39;@Url.Action(&quot;Index&quot;, &quot;Home&quot;)&#39;,
type: &#39;POST&#39;,
data: { empid: selectedEmpIdValue },
success: function (data) {
for (var i = 0; i &lt; data.length; i++) {
$(&#39;#displayEname&#39;).append(&#39;&lt;option value=&#39; + i + &#39;&gt;&#39;
+ data +
Here is My Controllers Code:-
PersonAccountInfoViewModel model = new PersonAccountInfoViewModel();
using (personalEntities db = new personalEntities())

model.getEname = new List<string>();
model.getobj = new List<empdetail>();

var emply = (from p in db.empdetails
select p);
var getEmpid = (from s in db.empdetails select s.empid);
model.getobj = emply.ToList();
model.getAlldeptNos = getEmpid.ToList();
var selectedDropdownId = (from d in model.getobj where d.empid == empid select d.ename);
model.getEname = selectedDropdownId.ToList();
return new JsonResult { Data = model.getEname };

Please any one can help me how to work with dropdownchecklist plugin or guide me is there any alternative to reach my requirement.Thanks in advance



(No response found.)

Login to post response