I am trying to write a javascript function that calls an Dictionary value and than tries to split it on a ´_’. The problem is that the Key to get the value from Dictionary is in an Javascript var that is extracted from a dropdownlist. Is it possible to use an Javascript var inside an c# function inside Javascript?
the Code as it is now:
var Category = document.getElementById('Properties').value;
var Name = document.getElementById(Category).value;
Category = '@Model.Dictionary[Name].Split('_')[0]';
EDIT:
People are misinterpreting my problem, the .Split function does work but the Dictionary[Name] is giving me problems. if i enter
var Category = document.getElementById('Properties').value;
var Name = document.getElementById(Category).value;
Category = '@Model.Dictionary["Bicycle"].Split('_')[0]';
into the code it works perfectly, but I want to get the “Bicycle” part dynamically out of an DropDownList.
EDIT 2:
Okay I have decided that what I am over thinking the situation and that what I am trying to do needs alot more work than is needed, found a beter solutions, thanks for everybody that tried to help me.
I have avoided the issue completely by having the DropDownList have different values in Value and Text, doing this is can get the wanted input that used to be in the Dictionary out of the Value of the DropDownList without changing the Text.