Can you just update a partial view instead of full page post?

后端 未结 5 1660
清酒与你
清酒与你 2020-12-23 17:04

Is there a way to submit a partial view form in asp.net mvc without reloading the parent page, but reloading the partial view only to its new state? Similar to how knockout.

5条回答
  •  孤城傲影
    2020-12-23 17:14

    In your Main View

    @Html.Partial("_NameOfPartialView", Model)

    In your Javascript file

    $('#btnSubmit').click(function () {
        GetData(Id);
    });
    
    function GetData(Id){
      $.ajax({
         url: "/Home/GetEmployee/",
         type: "get",
         data: { Id:Id },
         success: function (result) {
         $('#SearchResult').html(result);
         }
       });
    }
    

    In your Home Controller

    public ActionResult GetEmployee(int Id)
    {
       var employee= context.Employee.Where(x=> x.EmployeeId == Id)
    
       return this.PartialView("_NameOfPartialView", employee);
    }
    

提交回复
热议问题