Assigning ViewBag property in javascript

后端 未结 1 766
礼貌的吻别
礼貌的吻别 2021-01-21 20:10

I am trying to assign a JS variable to a ViewBag property and use that property in an Html ActionLink.

However, I\'m getting a design time compile error: \"Syntax error\

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 20:16

    This won't work. ViewBag works on server side and it will be out of scope when you get the response of an AJAX request. You should use JavaScript to update the values in your view once you get the response.

    You also get the error because an assignment should be in a code block:

    @{ ViewBag.CustomerID = data.CustomerID; }
    

    However this still won't work because data is a JavaScript variable.

    0 讨论(0)
提交回复
热议问题