Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

if (confirm('Are you sure?')){}

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top