Pan*_*bey 1 nhibernate asp.net-mvc jquery asp.net-mvc-3
我的控制器中有一个Web方法...
[WebMethod]
public IList<ThemeSelectList> GetThemesForSelectedCategory(string themeCategoryId)
{
IList<ThemeSelectList> themeSelectList = new List<ThemeSelectList>();
int emailLayoutThemeCategoryId = Convert.ToInt32(themeCategoryId);
using (var trans = session.BeginTransaction())
{
EmailThemeBusinessLogic emailThemeBusinessLogic = new EmailThemeBusinessLogic(session, null);
themeSelectList = emailThemeBusinessLogic.GetThemes(emailLayoutThemeCategoryId);
trans.Commit();
}
return themeSelectList;
}
Run Code Online (Sandbox Code Playgroud)
我试图从java脚本函数调用,即
function GetThemesForSelectedCategory(event)
{
event = event || window.event || e.srcElement;
event.preventDefault();
var selectedThemeCategoryId = $('#ddlThemeCategory option:selected').val();
var ThemeContainerDiv = $("#ThemeContenerDiv");
ThemeContainerDiv.html('<p><img src="../../../../Images/loading.gif"></p>');
$.ajax
({
type: "POST",
url: "GetThemesForSelectedCategory",
data: JSON.stringify({ "themeCategoryId": selectedThemeCategoryId }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// function is not returning to success
var ThemeDetails = data.d;
for (var i = 1; i <= ThemeDetails.length; i++) {
var row = ['<div id="' + ThemeDetails[i].ThemeId + '" class="themegroup divhighlight">\
<div class="themename">\
' + ThemeDetails[i].ThemeName + '\
</div>\
' + GetColourTamplate(ThemeDetails[i].ThemeTemplateColorList) + ''].join('\n');
}
},
error: function (xhr, ajaxOptions, thrownError) {
// always error method is getting called
var somthing = "pankajDubey";
},
complete: function (data)
{
var ThemeDetails = data.d;
for (var i = 1; i <= ThemeDetails.length; i++) {
var row = ['<div id="' + ThemeDetails[i].ThemeId + '" class="themegroup divhighlight">\
<div class="themename">\
' + ThemeDetails[i].ThemeName + '\
</div>\
' + GetColourTamplate(ThemeDetails[i].ThemeTemplateColorList) + ''].join('\n');
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
我无法理解出了什么问题.Web方法中的每件事都运行正常,但我不知道缺少什么.请帮忙,因为我是MVC和NHibernate的新手......
Dar*_*rov 10
我的控制器中有一个Web方法...
在ASP.NET中,MVC控制器有动作,而不是Web方法.Web方法已过时.
所以:
public ActionResult GetThemesForSelectedCategory(string themeCategoryId)
{
IList<ThemeSelectList> themeSelectList = new List<ThemeSelectList>();
int emailLayoutThemeCategoryId = Convert.ToInt32(themeCategoryId);
using (var trans = session.BeginTransaction())
{
EmailThemeBusinessLogic emailThemeBusinessLogic = new EmailThemeBusinessLogic(session, null);
themeSelectList = emailThemeBusinessLogic.GetThemes(emailLayoutThemeCategoryId);
trans.Commit();
}
return Json(themeSelectList);
}
Run Code Online (Sandbox Code Playgroud)
然后:
$.ajax({
type: "POST",
url: "/SomeControllerName/GetThemesForSelectedCategory",
data: { "themeCategoryId": selectedThemeCategoryId },
success: function (data) {
...
},
error: function (xhr, ajaxOptions, thrownError) {
...
},
complete: function (data) {
...
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10442 次 |
最近记录: |