I'm having a problem trying to get a ViewBage property value and pass it into a jQuery method. For example, in my code below, @ViewBag.CountResult have the value 1, and it is displayed in my browser, but when passed into the updateResultFooter method, it is like "" ! Don't get why. Down is my view. Any help ?
Thanks in advance
<div>
<div>
<span>Téléphone ?</span>
<input id="idTxTel" type="text" name="txTelephone"/>
<input id="idBnSearch" type="submit" value="Chercher" name="bnSearch"/>
</div>
@Html.Partial("_Result", Model)
</div>
<script type="text/javascript">
var methodUrl = '@Url.Content("~/Search/GetReverseResult/")';
$(document).ready(function (){
updateResultFooter("@ViewBag.CountResult", "@ViewBag.PageNumber", "@ViewBag.PageCount");
$("#idBnSearch").click(function (){
var telValue = $("#idTxTel").val();
pageIndex = 0;
doReverseSearch(telValue, pageIndex, methodUrl);
updateResultFooter("@ViewBag.CountResult", 0, "@ViewBag.PageCount");
});
$("#bnNextPage").live("click", function (){
var telValue = $("#idTxTel").val();
pageIndex = pageIndex + 1;
doReverseSearch(telValue, pageIndex, methodUrl);
updateResultFooter("@ViewBag.CountResult", pageIndex, "@ViewBag.PageCount");
});
});
function updateResultFooter(resultCount, pageIndex, pageCount){
if (resultCount == '0')
$("#resultFooter").hide();
else
{
$("#resultFooter").show();
if (pageIndex == 0)
$("bnPreviousPage").attr('disabled', 'disabled');
else
$("bnPreviousPage").removeAttr('disabled');
if ((pageIndex + 1) == pageCount)
$("bnNextPage").attr('disabled', 'disabled');
else
$("bnNextPage").removeAttr('disabled');
}
}
function doReverseSearch(telValue, pageIdx, methodUrl){
$.ajax({
url: methodUrl,
type: 'post',
data: JSON.stringify({ Telephone: telValue, pageIndex: pageIdx }),
datatype: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
$('#result').replaceWith(data);
},
error: function (request, status, err) {
alert(status);
alert(err);
}
});
}
</script>
PS: I'm using this code to modify the display of the web page, depending on the result of a search made by the user.