是否可以更新ViewBag变量?

时间:2014-03-06 17:31:53

标签: javascript jquery razor viewbag

可以使用页面上的javascript方法增加viewbag变量吗?我有以下尝试:

function ConfirmFriend(friendID, addOrDecline) {

      alert(addOrDecline);

      if (parseInt(@ViewBag.ActualFriendCount) == 0 && addOrDecline == "add")
      {             
          alert("THIS IS A FIRST ADD");
          @{
              int test = Convert.ToUInt32(@ViewBag.ActualFriendCount);
              test++;
              @ViewBag.ActualFriendCount == test;
          }
      }

    var userID = '@ViewBag.UserID';

    var postData = {
        'userID': userID,
        'userFriendID': friendID,
        'addOrDelete': addOrDecline
    };

    $.post('/User/Show/', postData, function (data) {
    });

    document.getElementById("HiddenPendingFriends" + friendID).style.display = 'none';

    if (addOrDecline == 'add') {
        document.getElementById("HiddenAcceptedFriends" + friendID).style.display = 'block';
    }
    else {
        document.getElementById("HiddenDeclinedFriends" + friendID).style.display = 'block';
    }
};

0 个答案:

没有答案