Search code examples
asp.net-mvc-3drop-down-menumodelclone

MVC3: Geting values of cloned objects


I have a drop down list with options from a model; and I want to add a similar drop down list when the user clicks on a button. My drop down list and button are defined as

<div id="parent">
    <div class="id">
        @Html.DropDownListFor(m =>m.mymodel)
    </div>
</div>
<input type="button" value="submit" onclick="JSFunc()"/>

And the function, JSFunc() is

var control = document.getElementById('id').cloneNode( true );
document.getElementById( 'parent' ).appendChild( new );

How can I get the value of the clone objects from the controller?


Solution

  • You must set the name attribute of a newly-created <select> to something unique that matches a parameter name in your controller.

    (or parameter property name, or anything else depending on the model binder and your situation)