how to pass a razor value to a jquery function, in an mvc view

后端 未结 6 1356
耶瑟儿~
耶瑟儿~ 2020-12-09 02:31

So I\'m trying to pass a parameter to a javascript function using the razor \'@\' notation (in an MVC-4 View) but I\'m getting Syntax error: \"Unterminated string constant\"

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 02:37

    As alternative, you may use the other way to get @item.ID in your jQuery function. Just add hiden span with it and get it's value in your function.

    Say, you have list:

      @foreach (var item in Model) { ...
    • @item.ID
    • }

    than in your script add:

    
    

    But to my mind better approach for jQuery is as follows:

        
      @foreach (var item in Model) { ...
    • @item.ID
    • }

提交回复
热议问题