Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using render partial concept in MVC. Its not showing the output in div. While debugging everything is OK (Showing Staus 200 OK) but its not going inside success block.Below is my jquery function.

C#
function ShowNavigation() {
var jsonObj = {
    'Display': 'Index',
    taFormula: $('#taFormula').val()
};
$.ajax(
    {
        url: "/Home/Index",
        type: "POST",
        data: jsonObj,
        dataType: "json",
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            var message = data.Message;
            $("#contentDiv").html(message).val();
        }
    });

}



My Controller code is:

C#
[HttpPost]
   public ActionResult Index(FormCollection collection)
   {
       var val = collection["taFormula"].ToString();
       ViewBag.Output = GetValue(val);
       return View();
   }
Posted

You may need to return your value in a JSONResult and not a View:

http://geekswithblogs.net/michelotti/archive/2008/06/28/mvc-json---jsonresult-and-jquery.aspx[^]

C#
[HttpPost]
public JsonResult Index(FormCollection collection)
{
   var val = collection["Formula"].ToString();
   var myValue = GetValue(val);
   return this.Json(myValue);
}


Your jQuery $.ajax call is set up to use Json but you're returning an ActionResult and not a JsonResult, which may well be the cause of your problems. You could also try adding an error: handler to your $.ajax call to see if there's some more information coming back:

http://api.jquery.com/jQuery.ajax/[^]
 
Share this answer
 
Comments
Sharad Mishra 20-Sep-11 7:13am    
@Jim I have tried with JsonResult as well but I am facing same problem. Also I have added an error handler to $.ajax like
error: function (xhr, status, error) {
alert(status + " : " + error);
},
and in alert I get "error : Internal Server Error".
Hi,

Using Jquery we can show results directly in thml tags like...

JavaScript
$("#tgid").load("/Home/Index",{},function(){alert("loading completed");});


or you can use this also

JavaScript
$.post("/Home/Index", {txt:"hi this is testing"}, function (data) {
 $("#tgid").html(data);
});


All the Best
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900