tags:

views:

28

answers:

1

I have 2 different lists: EmployeeNames and Names I read the values in Names and that of EmployeeNames.

If EmployeeNames exists in Names, I must not add that value to "ToSelectBox" but to "FromSelectBox".

If EmployeeNames doesn`t exist in Names, I must add that value to "ToSelectBox" but not to "FromSelectBox".

How can I do that dynamically?

I have 2 option values as follows:

<select id="fromSelectBox" multiple="multiple" > 

  <% foreach (var item in Model.EmployeeNames) { %> 
           <option value="<%=Html.Encode(Item.Text)%>"><%=Html.Encode(item.Text)%></option>  
        <%}  
    %> 
    </select> 

select id="ToSelectBox" multiple="multiple" > 

  <% foreach (var item in Model.Names) { %> 
           <option value="<%=Html.Encode(Item.Text)%>"><%=Html.Encode(item.Text)%></option>  
        <%}  
    %> 
    </select> 
+1  A: 

Hey,

You have to examine the data, and programmably control that. You can do that in the controller, where you can use Linq to check for the existence of a name in one list, and follow your business rules there, then pass the final lists to a model to pass to the view.

You could put that logic in your view, but that defeats the purpose of the controller and the separation of layers.

Brian