How to make update panel in ASP.NET MVC

前端 未结 3 1717
天涯浪人
天涯浪人 2020-12-04 06:24

How do I make an update panel in the ASP.NET Model-View-Contoller (MVC) framework?

3条回答
  •  甜味超标
    2020-12-04 06:55

    Basically the 'traditional' server-controls (including the ASP.NET AJAX ones) won't work out-of-the-box with MVC... the page lifecycle is pretty different. With MVC you are rendering your Html stream much more directly than the abstracted/pseudo-stateful box that WebForms wraps you up in.

    To 'simulate' an UpdatePanel in MVC, you might consider populating a

    using jQuery to achieve a similar result. A really simple, read-only example is on this 'search' page

    The HTML is simple:

    
    
    

    The data for the 'panel' is in JSON format - MVC can do this automagically see NerdDinner SearchController.cs

        public ActionResult SearchByLocation(float latitude, float longitude) {
            // code removed for clarity ...
            return Json(jsonDinners.ToList());
        }
    

    and the jQuery/javascript is too

      
      
    

    Of course UpdatePanel can be used in much more complex scenarios than this (it can contain INPUTS, supports ViewState and triggers across different panels and other controls). If you need that sort of complexity in your MVC app, I'm afraid you might be up for some custom development...

提交回复
热议问题