I have used jquery ajax twice in a single view. The first works fine, but the second sends the zero value as the input parameter to the corresponding action,I don't know why?
<tr>
<th>(@((int)ViewBag.BoonCount))</th>
<td class="text-right">
<input onchange="SetBoon()" class="form-control" type="number" name="Boon" id="MBoon" min="0" max="@((int)ViewBag.BoonCount)" value="" />
<script>
function SetBoon() {
var BoonVal = $('#MBoon').val();
$.ajax({
url: '/Users/SetBoon',
method: 'post',
contentType: 'json',
data: { fID: '@Factor.ID', BValue: BoonVal }
});
}
</script>
</td>
and it is my action code:
public string SetBoon(int fID, int BValue){}
The action receives zero as the input parameter.I even tested the @Factor.ID before entering the SetBoon function and had a valid value.
data: { fID: @Factor.ID, BValue: BoonVal }Factor.IDwhen the page is first rendered? What value are you expecting? You should be able to see from your rendered page source what it's passing. Does BValue get populated correctly?