首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在引导旅游中使用标题选项中的会话对象?

问如何在引导旅游中使用标题选项中的会话对象?
EN

Stack Overflow用户
提问于 2015-06-09 12:40:41
回答 1查看 139关注 0票数 0

我在我的应用程序中使用引导浏览。我想在引导旅游步骤中显示登录用户名。我的用户名存储在会话object.How中,我可以在标题中使用会话对象吗?

Js代码:

代码语言:javascript
复制
// Instance the tour
var tour = new Tour({
  steps: [
  {
    element: "#my-element",
    title: "Welcome to the tour" +'@Session["User"]',
    content: "Content of my step"
  },
  {
    element: "#my-other-element",
    title: "Title of my step",
    content: "Content of my step"
  }
]});

// Initialize the tour
tour.init();

// Start the tour
tour.start();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-09 13:35:30

您可以做的是,当获取视图页面加载时,将该session value绑定到ViewData或ViewBag,然后在js中获取类似的值

在控制器中

代码语言:javascript
复制
[HttpGet]
public ActionResult Index()
{
     //other codes
     ViewBag.UserName = Convert.ToString(Session["userName"]);
     return View();
}

在JS中

代码语言:javascript
复制
steps: [
  {
    element: "#my-element",
    title: "Welcome to the tour" +'@ViewBag.UserName',
    content: "Content of my step"
  },

更新:

在视图中添加一个隐藏字段如下:

代码语言:javascript
复制
<input type="hidden" id="hdnUname" value="@ViewBag.UserName" />

将其赋值给变量,如

代码语言:javascript
复制
var uname=$("#hdnUname").val() //or $("#hdnUname").attr('value');
steps: [
  {
    element: "#my-element",
    title: "Welcome to the tour" +uname,
    content: "Content of my step"
  },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30732309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档