Ashish Rathore
Ashish Rathore

Reputation: 2706

Use server side variable in jquery MVC 4

I'm having a server side global variable in my MVC4 application.

And now i need to use that variable in my View using j Query.

Can any one tell me how can i use that variable in my View using j Query.

Variable

namespace Saif.Models
{
    public class ClsGlobal
    {
        static string _AbsoluterUrl;
        public static string AbsoluterUrl
        {
            get { return _AbsoluterUrl; }
            set { _AbsoluterUrl = value; }
        }
    }
}

In J query $(document).ready

var url = @Saif.Models.ClsGlobal.AbsoluterUrl;

Upvotes: 2

Views: 1096

Answers (2)

Bart Beyers
Bart Beyers

Reputation: 3384

Try adding '' to the url in your javascript:

var url = '@Saif.Models.ClsGlobal.AbsoluterUrl';

The url will now contain the value of AbsoluteUrl.

Upvotes: 2

hungry
hungry

Reputation: 37

save server side variable value to hidden fields and then use hidden field value in jquery with the help of hidden fields id.

Upvotes: 0

Related Questions