【发布时间】:2016-06-04 08:54:16
【问题描述】:
Java 脚本:-
function themechange(themeValue) {
$('#themeId').attr('href', '/zcv/resources/css' + '/' + 'theme-' + themeValue.toLowerCase() + '.css');
$.ajax({
url: '@Url.Action("ChangeTheme", "Login")',
type: 'GET',
dataType: 'json',
cache: false,
data: { 'themeValue': themeValue },
success: function (data) {
alert(data);
},
error: function () {
alert('Error occured');
}
});
}
在 LoginContoller.cs 中:-
[HttpGet]
public JsonResult ChangeTheme(string themeValue)
{
System.Diagnostics.Debug.WriteLine("======ChangeTheme======");
Session["theme"] = themeValue;
String x= "========";
return Json(x, JsonRequestBehavior.AllowGet);
}
到目前为止回复的所有建议都不起作用。请提供 ASP.NET MVC 应用程序的可执行项目代码链接,该应用程序将简单的 ajax 与 json 应用于仅调用控制器方法。
【问题讨论】:
-
你确定控制器没有异常
-
ajax 请求是否进入控制器操作?
-
没有错误。 ajax 请求不会进入控制器操作
-
url: '/Login/ChangeTheme',现在试过了,但是ajax中没有进度错误函数正在加载
-
@Scripts.Render("~/bundles/jquery") 添加到视图页面解决了问题
标签: c# jquery asp.net json ajax