2015-06-09 17 views
0

我在我的應用程序中使用引導程序巡視。我想在引導程序巡視步驟的'標題'中顯示登錄用戶名。我的用戶名存儲在會話對象中。如何在標題中使用會話對象?如何在引導遊覽中的標題選項中使用會話對象?

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(); 
+0

哪個後端編碼您使用的? –

+0

我正在使用Asp.net Mvc5.im在控制器中存儲會話對象值,並且我在剃刀視圖中寫入了上述js – user3479588

回答

0

你可以做的是,當獲取查看[頁面加載]與該session valueViewDataViewBag,然後取像

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" 
    }, 
+0

嗨,它顯示「Welcome to the tour」+'@ViewBag.UserName'而不是顯示UserName的值我只是想顯示「歡迎來到xyz遊覽」如果UserName =「xyz」。 – user3479588

+0

@ user3479588。更新了答案!檢查並讓我知道! –

+0

It works.Thanks很多! – user3479588

相關問題