views:

367

answers:

4

Hi,

can anyone please tell about showing message box from MVC controller? The scenario is - I want to show a message box with Yes/No buttons. On clicking Yes i want to show a confirmation message box. I want to do this using MVC controller? How can I do this?

Thanks in advance, Kaps

A: 

Do you talking about client message box? If so, try use JavaScript's confirm dialog.

if (confirm('Are you sure?')){}
Mendy
I want to show the client message box but i want to show it from controller's action method.
kapil
In order the client will see a dialog, you need to send him this code. The <i>right</i> place to do such, is the view. but of course you can pass this code to the view from the action method.
Mendy
A: 

The Controller's action method generally does not control what the View renders, rather it simply states which view to display (ie. return this.View("MyView")) and the data the view should use to rendering itself if necessary.

You can use JavaScriptResult however you are breaking separation of concerns somewhat, the Controller should dictate which view to render, not what the view contains.

Here's a good write up on JavaScriptResult and why it's a bad idea: http://devlicio.us/blogs/billy_mccafferty/archive/2009/02/07/beware-of-asp-net-mvc-javascriptresult.aspx

James Webster
A: 

I think you want to do something like this:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

On the controller side you want the method to return json.

Tengiz
+1  A: 
if (confirm('Are you sure?'))
{
$.post("Confirmation", {myresponse: 'yes'}, function(data)
{
$.("#mymodal").html(data);
}
}

That way it hits the actionmethod and lets it know that a yes confirmation was made and the actionmethod can send back the html markup.

Al Katawazi