How to create an empty list and pass parameters without selecting them?

In my form, I move categories from one list to another as follows:
enter image description here

The bottom field is the input field that is read on the server side when the form is submitted. This is how I create the list:

<%: Html.ListBoxFor(m => m.categories, Model.categories)%>

I have two problems:

  • In Firefox , when the form is loaded for the first time, the bottom drawer is always the default <option></option>. Is it possible to remove this on the server side? IE seems to create an empty cell, but not FF.
    To solve this problem, I remove the blank parameter when the page loads. One of the problems is that when the form has an error and is not submitted, the parameters are deleted again.

  • , , . , jQuery , .


jQuery submit:

$("form").submit(function (event) {
    $("#categories").find("option").attr('selected', 'selected');  
});

jQuery :

$("#categories").find("option").remove();


1. , ?
2. ?

: , -, MVC.

+5
4

1: , , reset.

$('#mySelect option').each(function () {
    if(!$(this).val())
        $(this).remove();
});

http://jsfiddle.net/yWHLW/5/

+1

1. http://jsfiddle.net/wVWGm/ .

2

$("form").submit(function (event) {
    $("#categories").find("option:selected");  
});
+1

Firefox , , , select. , . № 2 №1.

jQuery click , , CSV Request.Form, , :

Request.Form("myHiddenInputName").Split({","c})

Or equivalent C # code. You will not need to select the items to send, and you will not have to worry about dropping the empty value that Firefox creates on the server side. Of course ... this may not be the most attractive workaround in the MVC architecture, but that was my first answer, so I decided to share it.

+1
source

Why don't you create a list box using simple HTML; instead of using an assistant

<select style="width: 370px;" class="cmbBox1" id="ServicesList" 
multiple="multiple" name="ServicesList" size="8"></select>
0
source

All Articles