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.
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:
[HttpPost]
public ActionResult Index(FormCollection collection)
{
var val = collection["taFormula"].ToString();
ViewBag.Output = GetValue(val);
return View();
}
Remove the
datatype: "json"bit. You’re receiving html back from the server, not json data, but because of that setting it’s trying to parse it and failing. If you had an error callback function it would go into that.Also, you don’t need the
.val()on$("#contentDiv").html(message).val();Try adding an error handler to the ajax call and see if that gives you any more information:
Try this for your json object:
You might need to include json.js for older browsers.