How to pass a value to razor variable from javascript variable?

后端 未结 7 1011
小鲜肉
小鲜肉 2020-11-27 19:43

How to pass a value to razor variable from javascript variable, is it possible asp.net mvc razor view engine?

@{
    int a = 0;
}



        
7条回答
  •  清歌不尽
    2020-11-27 20:31

    I see that this problem was discussed some time ago, but if anyone 'll meet with this again, here is my solution:

    In your *.cshtml View file:

    
    

    JavaScript variable model is something that I need to pass to Razor ViewModel. It can be done with ajax request. You just need to have proper argument/s in your action, that matches Json object created in JavaScript.

    Hope it'll help someone!

提交回复
热议问题