I want to pass javascript variable in the C# method which is call from the Razor page. May I know how can I do that? (I refer this link but it did not work for me.)
You can't do something like this, because razor works in render time of the page. UserID is not available at render time, thats why you can not pass it as a variable to servercode.
if you need to call SomeMethod on runtime, you can make a ajax request for it.
You will need to make an ajax call and resolve the parameter server side, or create a client side equivalent of the function you are using in razor syntax. Look for ajax tutorials if you have no experience with it, i hear jQuery is very good.