Twitter bootstrap 如何在引导程序中使用标题选项中的会话对象?
我正在应用程序中使用引导程序。我想在引导程序步骤的“标题”中显示登录用户名。我的用户名存储在会话对象中。如何使用标题中的会话对象 Js代码:Twitter bootstrap 如何在引导程序中使用标题选项中的会话对象?,twitter-bootstrap,Twitter Bootstrap,我正在应用程序中使用引导程序。我想在引导程序步骤的“标题”中显示登录用户名。我的用户名存储在会话对象中。如何使用标题中的会话对象 Js代码: // Instance the tour var tour = new Tour({ steps: [ { element: "#my-element", title: "Welcome to the tour" +'@Session["User"]', content: "Content of my step" },
// 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();
您可以做的是,当Get View[page load]将该会话值绑定到ViewData或ViewBag,然后在js中获取该值 内部控制器
[HttpGet]
public ActionResult Index()
{
//other codes
ViewBag.UserName = Convert.ToString(Session["userName"]);
return View();
}
在JS中
更新:
在视图中添加隐藏字段,如下所示:
<input type="hidden" id="hdnUname" value="@ViewBag.UserName" />
您使用的是哪种后端编码??我使用的是Asp.net Mvc5。我在控制器中存储会话对象值,我在razor viewhi中写过上面的js,它显示欢迎访问+'@ViewBag.UserName'而不是显示用户名的值。如果UserName=xyz,我只想显示欢迎访问xyz。@user3479588。更新了答案!!检查并让我知道!!随时快乐编码..:
<input type="hidden" id="hdnUname" value="@ViewBag.UserName" />
var uname=$("#hdnUname").val() //or $("#hdnUname").attr('value');
steps: [
{
element: "#my-element",
title: "Welcome to the tour" +uname,
content: "Content of my step"
},