Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I have an issue where I submit my form on completion of a javascript function.

The submit works, but it loses the values in my model.

<script type="text/javascript">
    function changeSubjectPhaseForStudent(subjectID, studentID) {
        var theForm = document.getElementById("frmStudent");

        theForm.submit();
    }
</script>

@model StudentController.StudentMetrics 
    
@using (Html.BeginForm("Student", "Student", Model,FormMethod.Get, new { id = "frmStudent" }))
{
@Html.DropDownListFor(x => x.PhaseID, (List<SelectListItem>)ViewBag.Phases, new { onchange = string.Format("changeSubjectPhaseForStudent({0},{1})", Model.SubjectID, Model.StudentID), id = "cmbPhase" })
}


Under normal circumstances, the model retains its values when it submits back into the controller. It's only when the form is submitted via the above jscript that it returns only a few values, not all.

Can anyone see what I am doing wrong???

Thanks in advance.
Posted
Updated 7-May-13 11:35am
v2

1 solution

Inside your form, you should add the model values, like this:
ASP.NET
@Html.HiddenFor(m => m.SubjectID)
@Html.HiddenFor(m => m.StudentID)
 
Share this answer
 
Comments
Unsy 7-May-13 18:40pm    
That did the trick. Thank you very much. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900