Hi i got to use c# code in js. My js and .cshtml page are separeted . I wrote a function in .cshtml page and gotta call it in .js file.
In Js file
DataList.forEach(function (item) {
...
var users = GetUsers(item.AssignedUsers);
It goes here
Index.cshtml
<script>
function GetUsers(userIdList) {
//it logs it, i can get theese values from here
console.log("userIdList");
console.log(userIdList);
@{ // but in here it says userIdList does not exist in current content
//also tryed this.userIdList
var users = userIdList.Split(",");
foreach (var item in users)
{
var user = _Manager.FindByIdAsync(item.UserId).Result;
}
}
}
</script>

in here it says userIdList does not exist...yes because it's a JavaScript variable not a c# variable. You can't just mix the languages together like that. They are executed at different times and in different places (browser for JavaScript, server for c#). If you need to invoke some c# based on values generated by JavaScript then the obvious thing to do would be to make an AJAX request to the server which can then execute the c# and return a response