我在我的应用程序中使用引导浏览。我想在引导旅游步骤中显示登录用户名。我的用户名存储在会话object.How中,我可以在标题中使用会话对象吗?
Js代码:
// 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();发布于 2015-06-09 13:35:30
您可以做的是,当获取视图页面加载时,将该session value绑定到ViewData或ViewBag,然后在js中获取类似的值
在控制器中
[HttpGet]
public ActionResult Index()
{
//other codes
ViewBag.UserName = Convert.ToString(Session["userName"]);
return View();
}在JS中
steps: [
{
element: "#my-element",
title: "Welcome to the tour" +'@ViewBag.UserName',
content: "Content of my step"
},更新:
在视图中添加一个隐藏字段如下:
<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"
},https://stackoverflow.com/questions/30732309
复制相似问题