I am using C# asp.net mvc3. In one of my views, say I declare a variable like this:
@{
ViewBag.Title = "title"
string mystr;
}
I need to set the value of the variable mystr in a function of the script. How do I access this variable from the script? Suppose I have a function like
<Script type="text/javascript">
function(){
var st = "This string is for the global variable"
mystr = st;
}
</script>
mystr will later be used in the html code like this:
<h2>@mystr</h2>
.
Is there a similar way of accessing a variable from a function?