I'm trying to return a partial view in asp mvc2 rendered with spark. The view contains some javascript. Everything gets rendered but the script does not execute
here is the code
<table>
<tr>
<td>
!{Html.LabelFor(model => model.SourceId, new { @class = "label-inline", title = "Source d'ouvrage" })}
!{Html.DropDownList("SourceList", Model.SourceList, "Choisir la source", new { @class = "combo-box" })}
</td>
<td>
!{Html.LabelFor(model => model.AgentId, new { @class = "label-inline", title = "Représentant" })}
!{Html.DropDownList("AgentList", Model.AgentList, "Choisir le représentant", new { @class = "combo-box" })}
</td>
</tr>
<script type="text/javascript">
$("#SourceList").change(function() {
alert('youpi');
$.ajaxSetup({ cache: false });
var selectedItem = $(this).val();
alert(selectedItem);
if (selectedItem == "" || selectedItem == 0) {
//Do nothing or hide...?
} else {
var path = '~/sources/' + selectedItem + '/agents';
$.getJSON(path, function(data) {
agents = data;
var items = "";
$.each(data, function(i, agents) {
items += "<option value='" + agents.Id + "'>" + agents.Name + "</option>";
});
$("#AgentList").html(items);
});
}
});
</script>
What i'm i doing wrong? thanks