开发者

How to show Messagebox from MVC Controller

开发者 https://www.devze.com 2022-12-19 10:50 出处:网络
开发者_开发技巧can anyone please tell about showing message box from MVC controller? The scenario is -

开发者_开发技巧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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消