'Accessing the session data in bootstrap wizard
I'm trying to create a customer survey form and I used a bootstrap wizard to navigate through the questions.
So here in the first section, there is a dropdown list for users to select the language.
When the user selects a language I wrote a javascript to get the selected value and pass to the controller and assign it to the session.
So in the next section, I want to show the questions by the selected value which is now stored at the session.
Don't know the method I tried to create this is right or wrong but I realize that it's only read the session data on load.
So is there any way to do this change with the selected value from the first dropdown?
This is the first step
<form action="" id="wizard">
<!-- SECTION 1 -->
<h4></h4>
<section>
<h3>Please select the Language</h3>
<div class="form-row center">
<div class="form-holder center "> @Html.DropDownListFor(model => model.Language, new SelectList(new[] { "English", "සිංහල", "தமிழ்" }),"Please Select the Language", new { @class = "form-control js-dropdown",Id ="DropLanguage" }) </div>
</div>
</section>
This is the script that collects the selected value and passes to the controller to set it to the session
< script type = "text/javascript" >
$(document).ready(function () {
$("#DropLanguage").on("change", function () {
// This is the jQuery way of finding selected option's text
var myVar = $(this).find("option:selected").text();
// Post the value to your server. You should do some error handling here
$.post("/MainDetails/SetSession", {
myVariable: myVar
});
});
}); <
/script>
This is the controller that set the value of the session.
[HttpPost]
public ActionResult SetSession(string myVariable) {
// Set to Session here.
Session["SelectedLanguage"] = null;
if (myVariable == "English") {
Session["SelectedLanguage"] = "Secondary";
} else if (myVariable == "සිංහල") {
Session["SelectedLanguage"] = "Primary";
} else if (myVariable == "தமிழ்") {
Session["SelectedLanguage"] = "Third";
}
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
So in the next section I tried this,
@if (@Session["SelectedLanguage"].ToString() == "Primary")
{
<h3>Customer Details</h3>
}
else if (@Session["SelectedLanguage"].ToString() == "Secondary")
{
<h3>Customer Details - Language 2</h3>
}
But this if not triggered . it's only triggered with the form load.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
