Updating PartialView mvc 4

前端 未结 4 1819
广开言路
广开言路 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条回答
  •  醉梦人生
    2020-11-30 05:27

    So, say you have your View with PartialView, which have to be updated by button click:

    @{ Html.RenderAction("UpdatePoints");}

    There are some ways to do it. For example you may use jQuery:

    
    

    PostActionToUpdatePoints is your Action with [HttpPost] attribute, which you use to update points

    If you use logic in your action UpdatePoints() to update points, maybe you forgot to add [HttpPost] attribute to it:

    [HttpPost]
    public ActionResult UpdatePoints()
    {    
        ViewBag.points =  _Repository.Points;
        return PartialView("UpdatePoints");
    }
    

提交回复
热议问题