ycs
ycs

Reputation: 77

return string value to html in mvc

I am trying to put string value to my view page it's something like this

public static  class ExtensionMethods
{
    public static string ItemApiURL()
    {
        return WebConfigurationManager.AppSettings["ItemApiLocation"];            
    }
 }

this will read my web config value and return the value to my view page java script

<script>
var itemApiUrl = @ExtensionMethods.ItemApiURL().ToString();
</script>

but I am getting in runtime like this var itemApiUrl = http://example.com:22273/odata/ItemQC?

as it is no quotation " " this give me error for me Any thought??

Upvotes: 0

Views: 59

Answers (1)

jhdrn
jhdrn

Reputation: 187

A javascript string needs to be quoted:

<script>
var itemApiUrl = '@ExtensionMethods.ItemApiURL().ToString()';
</script>

Upvotes: 1

Related Questions