问题
I am aware that Razor is server side and Javascript client side. I am trying to workaround this. Here's what I wanted:
RAZOR:
if (count > 0)
{
t.Add().Text("Yeah")
...
...
}
}
But that count is defined at the beginning of the View, like this:
@{
int count = 2;
}
But I can't define it like that: the value for count
is on a javascript variable, set on document.ready
. Then, I want to use it in the Razor if condition.
Is it possible to workaround this?
回答1:
Simply No , The reason is same server-side language run first, than after browser run client side languages, So you can use server side variables values in client side language, you can generate client side code from server side but this all will not work in vice-versa,
The option you have for your problem is only Ajax request
来源:https://stackoverflow.com/questions/33957996/using-a-javascript-variable-within-razor