Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using jquery plugin to add checkbox in dropdown list.
I do not include $(document).ready, dropdown list works as single selection and I can get value in model.WorkplaceID in control`enter code here`ler. but if I include $(document).ready, its showing blank in model.WorkplaceID in controller. On using $(document).ready, items are selected in span. I guess view in not able to set that value in UserModel model. How can i pass value in controller???

My code goes like this.


$(document).ready(function () {
    $("#WorkplaceID").dropdownchecklist();
});


--To display control in view

@model Kats.DAL.UserModel
@{
    ViewBag.Title = "Createuser";
    Layout = "~/Areas/SuperAdmin/Views/Shared/_Layout.cshtml";
    List<SelectListItem> WorkPlaces = (List<SelectListItem>)ViewBag.WorkPlaces;
}

<li>
    @Html.LabelFor(m => m.WorkplaceID, "Workplace:")
    @Html.DropDownList("WorkplaceID",  WorkPlaces)
    @Html.HiddenFor(m => m.Workplace)         
</li>


$(document).ready(function(){
    $("#WorkplaceID").dropdownchecklist();
});



-- To bind jquery plugin for check box selection in dropdown



Here, if I don't include $(document).ready, dropdown list works as single selection and I can get value in model.WorkplaceID in control`enter code here`ler. but if I include $(document).ready, its showing blank in model.WorkplaceID in controller. On using $(document).ready, items are selected in span. I guess view in not able to set that value in UserModel model. How can i pass value in controller???



--Get value in controller for db related action

C#
[HttpPost]
public ActionResult Create(UserModel model)
{
    String wp == model.WorkplaceID;
}


What I have tried:

On checking DOM, I found out that on multiple selection, item is being created on span. Is it the m.Workplace is not able to read value of span??
Posted
Updated 24-Jul-16 5:19am
v5

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