Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a web method in My Controller...

    [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;            
    }

that i am trying to call from a java-script function, that is

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');
            }
        }
    });
}

i am unable to understand what is going wrong. Every Thing in web method is working fine but i don't know what is missing. please help as I am new to MVC and NHibernate both...

share|improve this question
    
what is the error you are getting? –  Igarioshka Jun 4 '13 at 6:55
add comment

1 Answer

up vote 6 down vote accepted

I have a web method in My Controller...

In ASP.NET MVC controllers have actions, not web methods. Web methods are obsolete.

So:

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);
}

and then:

$.ajax({
    type: "POST",
    url: "/SomeControllerName/GetThemesForSelectedCategory",
    data: { "themeCategoryId": selectedThemeCategoryId },
    success: function (data) {
        ...
    },
    error: function (xhr, ajaxOptions, thrownError) {
        ...
    },
    complete: function (data) {
        ...
    }
});
share|improve this answer
    
Thanks for response i am going to try the same... –  Pankaj Dubey Jun 4 '13 at 7:19
    
thanks for your answer.. instead of ActionResult i used JsonResult.. and That Solved My Problem –  Pankaj Dubey Jun 4 '13 at 8:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.