0

I use jQuery for two DropdownList elements in MVC. But both classes are equally named "chzn-select". When I try to add values there are some conflicts.

Can anybody tell me how to distinguish the "chzn-select" elements?

<tr>
    <td>@Html.Label("branch")
    </td>
    <td>
        @Html.DropDownListFor(m => m.RegionId, (SelectList)ViewBag.Regions, new {@class="chzn-select" ,multiple ="true",data_placeholder = "choose branch", style = "Width:200px", onChange = "regionDropDownChanged();" , tabindex = 3   })
        @Html.ValidationMessageFor(m => m.RegionId)
    </td>
</tr>
<tr>
    <td>@Html.Label("organization")
    </td>
    <td>
        @Html.DropDownListFor(m => m.EnterpriseId, (SelectList)ViewBag.Enterprises, new {@class="chzn-select" ,multiple ="true",data_placeholder = "choose organization", style = "Width:200px", tabindex = 3 })
        @Html.ValidationMessageFor(m => m.EnterpriseId)
    </td>
    <td>
    </td>
</tr>
4
  • remove "@" sign before class="chzn-select"... and see. Commented Jun 29, 2013 at 8:05
  • Im MVC you must use @. If you dont use it will occur error.
    – user1093896
    Commented Jun 29, 2013 at 8:08
  • well @ is to start of a code block, its the razor syntax to indicate code. Commented Jun 29, 2013 at 8:11
  • but when I delete @ it give me error
    – user1093896
    Commented Jun 29, 2013 at 8:50

3 Answers 3

0

You can also add custom attribute like isstyleadded=true, which will allow you to make choice.

1
  • did you use jquery or javascript to get this attribute? eg: var x = $('[isstyleadded=true]') ?
    – mehul9595
    Commented Jun 29, 2013 at 9:40
0

You can add an ID or add a new class like this @class="chzn-select-branch chzn-select".

So chzn-select is use to style to dropdonw and chzn-select-branch to add items with jQuery

1
  • Try using @class="chzn-select-branch chzn-select". So with jquery do somethink like this $(".chzn-select-branch") Commented Jun 29, 2013 at 9:41
0

I agree with @alecasciaro. I've noticed I've been mostly adding a class name to help with selectors. Comes in handy when dealing with specific groups of elements.

I tried to vote for that answer but I guess I don't yet have enough reputation points to do anything but Ask or Answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.