Reputation: 75
I have created a function in controller in which I have created three sessions and passed the values. I need to pass the values to some variables in jquery file to use it in a function. Here is the controller function
public string GetAssociatedCompSetsForGroup(string groupID, string ScreenName)
{
Session["WorkBookID"] = Session["workbookId"];
Session["groupID"] = groupID;
Session["ScreenName"] = ScreenName;
IList<int> compSetsIds = serviceKMALocator.InvokeService<IList<int>>(x => x.GetAssociatedCompSetsForGroup(Convert.ToInt32(groupID), ScreenName));
string ids = string.Empty;
foreach (int id in compSetsIds)
{
ids = ids + id.ToString() + Constant.SemiColon;
}
if (!string.IsNullOrEmpty(ids))
{
ids = ids.Substring(0, ids.Length - 1);
}
ViewBag.CompSetIds = ids;
Session[Constant.CompSetIds] = compSetsIds;
return ids;
}
and the values of three sessions i have created in the controller should be passed to the variables in the following code and i have tried something like this.
var GroupID = '<%=Session("groupID")%>';
var WorkBookID = '<%=Session("WorkBookID")%>';
var ScreenName = '<%=Session("ScreenName")>';
if (GroupID != null && WorkBookID != null && ScreenName != null)
{
$.post(compsetForGroup, { groupID: GroupID, ScreenName: ScreenName }, function (jsonData) {
if (jsonData) {
function ajaxCall(no) { .....
Please help me with the correct format. Thankyou in advance.
Upvotes: 0
Views: 3383
Reputation: 5590
This is how I've done it
var OppoId = '@(OMSSession.SessionProperties.SelectedOpportunityId)';
Upvotes: 0
Reputation: 185
in your JavaScript Codes:
var WorkBookID = "@Session[0]";
var groupID= "@Session[1]";
var ScreenName = "@Session[2]";
that sessions 0 to 2 is equivalence to the value of WorkBookID ,groupID,ScreenName sessions Respectively.
Upvotes: 1
Reputation: 35803
Try this:
var GroupID = '<%=Session["groupID"]%>';
var WorkBookID = '<%=Session["WorkBookID"]%>';
var ScreenName = '<%=Session["ScreenName"]>';
if (GroupID && WorkBookID && ScreenName)
{
Upvotes: 0