Updating PartialView mvc 4

前端 未结 4 1869
广开言路
广开言路 2020-11-30 04:40

Ey! How I could refresh a Partial View with data out of the Model? First time, when the page loads it\'s working properly, but not when I call it from the Action. The struct

4条回答
  •  猫巷女王i
    2020-11-30 05:25

    You can also try this.

     $(document).ready(function () {
                var url = "@(Html.Raw(Url.Action("ActionName", "ControllerName")))";
                $("#PartialViewDivId").load(url);
            setInterval(function () {
                var url = "@(Html.Raw(Url.Action("ActionName", "ControllerName")))";
                $("#PartialViewDivId").load(url);
            }, 30000); //Refreshes every 30 seconds
    
            $.ajaxSetup({ cache: false });  //Turn off caching
        });
    

    It makes an initial call to load the div, and then subsequent calls are on a 30 second interval.

    In the controller section you can update the object and pass the object to the partial view.

    public class ControllerName: Controller
    {
        public ActionResult ActionName()
        {
            .
            .   // code for update object
            .
            return PartialView("PartialViewName", updatedObject);
        }
    }
    

提交回复
热议问题