AJAX call on OnChange event in MVC

前端 未结 5 938
温柔的废话
温柔的废话 2021-01-02 19:39

I have to make an AJAX call on the onchange event of a dropdownlist which is part of a view. On the change event i need to call the database, do some calculations display th

5条回答
  •  被撕碎了的回忆
    2021-01-02 20:07

    Here is a general idea how you'd implement this.

    
    
    
    
    
    
    <%= Html.RenderPartial("MyPartialView", Model) %>

    Here is your controller action method.

    [HttpPost]
    public PartialViewResult GetPartialGraph(int id /* drop down value */)
    {
        // do calculations whatever you need to do
        // instantiate Model object
        var model = myBusinessLogicService.DoCalculations(id);
    
        return PartialView("MyPartialView", model);
    }
    

    I think this is the answer you are looking for.

提交回复
热议问题