jquery - 在 jquery MVC 4 中使用服务器端变量

标签 jquery asp.net-mvc-4

我的 MVC4 应用程序中有一个服务器端全局变量。

现在我需要使用 j Query 在我的 View 中使用该变量。

谁能告诉我如何使用 j Query 在 View 中使用该变量。

变量

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

在J查询$(document).ready
var url = @Saif.Models.ClsGlobal.AbsoluterUrl;

最佳答案

尝试将 '' 添加到 JavaScript 中的网址:

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

url 现在将包含 AbsoluteUrl 的值。

关于jquery - 在 jquery MVC 4 中使用服务器端变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22216728/

相关文章:

javascript - AJAX在html正文中显示html页面

c# - 在发布之前重新显示所有表单输入

asp.net - 如何结合 ASP MVC 5 和 Emberjs

javascript - jQuery 按钮只能工作一次

javascript - 仅在单击时运行 javascript src

jquery - 为什么 z-index 被位置 :static? 忽略

c# - JSON 数组而不是字符串

c# - 部分加载时运行 Javascript/Jquery

c# - asp.net MVC 路由顺序

javascript - 如何在div的底部保持滚动条?