I have a value in my span, which i want to compare with C# variable, is it possible ?? If yes, then How ??
I can get the Html tag values in Jquery variable, but still not succeeding to get it to compare it with a C# variable value in Razor View.
HTML Tag: <span style="visibility: hidden" id="category">"Some Value"</span>
C# Razor Syntax :
@foreach (var item in Model.InventoryViewModel.Items.Where(i => i.Category == "HTML Value"))
{
// Some Code
}
I am trying to match the value in span with C# variable, any help suggestions please :\ !!
no idea what you are doing but you could use a variable or something, or even better a property on your view model. Anyway Razor code runs on the server, HTML is on the client so talking about comparing HTML values in Razor is like the chicken and egg problem.
So you could generate your pan tag with a value of your view model:
and then you compare:
but even better would be to perform this on the controller action and directly filter the collection so that all you have to do in the view is:
or even shorter using templates: