0

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.

4

1 回答 1

0

我改变了我使用的方法。现在,我更改了模型,使其包含我想要显示的数据,例如 ( CountResult, PageCount)。现在它工作正常。

于 2012-07-29T12:38:18.110 回答