MVC Ajax UpdatePanel

2019-04-08 06:53发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-04-08 07:14

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

查看更多
走好不送
3楼-- · 2019-04-08 07:15

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. :)

查看更多
登录 后发表回答