views:

21

answers:

1

Hi,

Am new to this and just trying to submit dynamically populated select list on POST in MVC.

Have read this post but don't quite understand the details of the solution, or simply can't get it to work.

Here's my code:

$(document).ready(function () {
    $("#SpecificID").hide();
    $("#ObjectKindID").change(function () {             
        $.getJSON("/Client/GetSpecificClientDDL", { objID: $(this).val(), ajax: 'true' }, function (data) {
            fillSelect($("#SpecificID"), data);
        });
        $("#SpecificID").show();
    });
});

function fillSelect(selectList, data) {
    selectList.html('');
    $.each(data, function (index, optionData) {
        selectList.append($('<option></option>').val(optionData.Value).html(optionData.Text));
    });
}

$(document).submit(function() {
    $("#SpecificID").find('option').attr('value', true);
});

Any help greatly appreciated - I expect (and hope) it is something stupidly simple...

Cheers.

Tim.

A: 

I solved it.

My problem was I didn't understand the .submit() function. What worked in the end was simply:

$(document).submit(function() {
    $("#SpecificID").val();
});

I was getting "could not update model" error. It may have been that my old code for submit function was returning a STRING and not an INT (as my model requires), since the attr() returns a string (http://api.jquery.com/attr/). Stepping through the code, the SpecificID was always "0" regardless of the value. Maybe this explains it.

So in the end it was that simple really.

nulliusinverba