i trying send string value controller action on view using view bag this
public actionresult services() { viewbag.tabval = "earnmoney"; return view(); } on view assigning view bag value javascript variable this
@section scripts{ <script> var tab = @viewbag.tabval; console.log(tab); </script> } on console value
<li id="earnmoney"> earnmoney</li> which html element on view.
why selecting element on view , not giving string in return ?this weird behavior.
you output viewbag value directly javascript, without quote, it's not string in javascript. html generated server looked this:
var tab = earnmoney; and since there's dom element id, selects element instead
put viewbag output in quote instead:
var tab = "@viewbag.tabval";
Comments
Post a Comment