nccsbim071 25 Junior Poster

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  <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"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.