Display success/failiure message in Jquery modal coming of a controller Viewdata

I have a master detail screen In ASP.NET MVC, when I submit something, It instantly returns to me a grid with the inserted value via Ajax, my problem is: I want to pass a message of failiure or successful via an jquery modal dialog or infobar and I can't pass a viewdata for the jquery to process It. Any ideas?

-------------Problems Reply------------

The action method that you are invoking through AJAX needs to return everything that's needed in the response. So for example when you put some object inside ViewData, this object will be available inside the View (or probably the partial view) that you are returning from the action and so available to the calling javascript. Another option is to return JSON object containing the message:

public ActionResult SomeAction()
{
// ...
return Json(
new { Message = "Success Message!" },
JsonRequestBehavior.AllowGet
);
}

which could be invoked like this:

$.getJSON('/somecontroller/someaction', function(json) {
alert(json.Message);
});

You can put this tag inside the script call.

var msg = '<%= ViewData["Mensagem"] %>';
alert(msg);

Don't forget to encode strings.

Category:jquery Views:0 Time:2010-04-23

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.194 (s). 11 q(s)