locked
Read Json result returned by ASP.NET MVC Controller RRS feed

  • Question

  • Hi,
    i hava a dropdownlist in asp.net mvc page. On selecting particular select item from dropdownlist i have made an ajax post request to the controller method that returns me the result. Everything is working fine. i also get the required result. But the problem is how shall i extract required things from json result.

    Here is my ajax request:

      <script type="text/javascript">
    function getContent() {
                var Sid = document.getElementById("hdnSectionId").value;          
                var Lid = document.getElementById("DdLanguageTrans").options[document.getElementById("DdLanguageTrans").selectedIndex].value;
                var sectionOrder = document.getElementById("hdnSectionOrder").value;
                $.ajax({                              
                    type: "POST",
                    url: "/AjaxRequest/ControllerMethod",               
                    data: "Sid=" + Sid + "&Lid=" + Lid + "&sectionOrder=" + sectionOrder,
                    success: function(result) {              
                    alert(result);
                    },
                    error: function(req, status, error) {
                        alert("Error occured.");
                    }
                });
            }
           
        </script>

    Here is my controller method:

    public JsonResult ControllerMethod(int Sid, int Lid, int sectionOrder)
            {
                try
                {
                    HomeCMS content = new HomeCMS();
                   
                    HomeCMS CMS = _service.HomeContentRepository.GetAllBySectionIdTransTest(Sid, Lid, sectionOrder);
                    content.Title = CMS.Title;
                    content.Content = CMS.Content;             
                    return Json(new { Title = content.Title, Content= content.Content});               

                }
                catch
                {
                    JsonResult res = new JsonResult
                    {
                        Data = false
                    };
                    return res;
                }
            }


    Everything is fine. I can only see result by alert. How can is just read the result. Something like this "result.Title" and "result.Content"
    • Moved by liurong luo Thursday, January 28, 2010 1:07 AM off-topic issue. (From:Visual Studio Debugger)
    Wednesday, January 27, 2010 4:08 AM

Answers

  • Hello,

    This forum is about Visual Studio Debugger. Basically, it is off-topic here. Please post threads in ASP.NET forums for better support. Hope you could understand.

    Best regards
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by nccsbim071 Monday, April 5, 2010 3:49 PM
    Wednesday, January 27, 2010 7:40 AM

All replies

  • Hello,

    This forum is about Visual Studio Debugger. Basically, it is off-topic here. Please post threads in ASP.NET forums for better support. Hope you could understand.

    Best regards
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by nccsbim071 Monday, April 5, 2010 3:49 PM
    Wednesday, January 27, 2010 7:40 AM
  • Thanks for advice. I will post this question in other asp.net forums.

    Is it possible to delete this post.
    Wednesday, January 27, 2010 10:21 AM
  • This might help you i.e. http://bit.ly/2o8PMkt

    Thanks & regards, Asma Khalid web: www.asmak9.com

    Monday, July 24, 2017 8:11 AM