MVC Ajax UpdatePanel

感情迁移 提交于 2019-12-21 15:48:29

问题


I know (at least i'm pretty sure) there isn't a control for MVC like the asp:UpdatePanel. Can anyone give me some idea on how to do this.

I have a collection that i add entries to from my repository & services layers. in my masterpage i would like to show an alert depending on if there is anything in this collection.

Normally i would have an UpdatePanel whose UpdateMode="Always" and it would check the collection and display my messages.

Do you know how i can achieve something similiar in MVC?


回答1:


Stay away from the UpdatePanel concept all together.

ASP.NET MVC includes jQuery, which is fully supported by Microsoft now. You will want to create partial views (RenderPartial) that make calls back to a method on a controller, that returns JSON.

Then, use jQuery to wire up the control and partial views.

jQuery is an extremely powerful javascript library. I highly recommend the book jQuery in Action as a reference when diving into the ASP.NET MVC /Scripts/jquery-x.x.x.js files. :)




回答2:


I use Ajax.BeginForm() with a partial view callback. and do all my code behind in the controller. works like a charm and you can even overload all the methods like OnSuccess OnFailure and OnComplete. There is a lot of functionality using this. :P



来源:https://stackoverflow.com/questions/611620/mvc-ajax-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!