【发布时间】:2018-07-29 10:11:09
【问题描述】:
我在控制器中创建了一个方法并尝试从中读取会话变量值,我正在从 Ajax jQuery 调用此方法,但我无法获取该值。 还有另一种方法,我试图读取会话值并从控制器本身调用它,然后我可以读取。 我在 MVC .Net 中的会话工作不多。请看我的代码-
$("#Value").on('click', function () {
$("#Modal").modal("hide");
$.ajax({
type: "GET",
url: "Home/GetData",
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { flag: 1, Id: '@employeeId' },
cache: false,
success: function (data) {
if (data == 'True') {
console.log("Data Saved")
}
}
});
});
GetData 方法是用 HomeContoller 编写的,我在 Homecontoller 的 Index 方法中分配 Key。
public async Task<JsonResult> GetData(int Flag, string EmployeeId)
{
string Token= string.IsNullOrEmpty((string)System.Web.HttpContext.Current.Session["Key"]) ? string.Empty : (string)System.Web.HttpContext.Current.Session["Key"];
}
【问题讨论】:
-
没有完全理解您的问题,能否请您添加代码以更清晰。
-
分享相关代码
-
感谢您的快速回复。我已添加编码-请您查看并提出建议。
标签: ajax asp.net-mvc session