REFRESH PARTIAL VIEW IN MVC4

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
 4133  View(s)
Ratings:
Rate this:
these days i'm working on a project, based on MVC 4.
i have to requirement to refresh partial view which use to display data from database on a view.
this partial view refresh only not whole view page?

thanks
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Refresh partial view in mvc4

    Hi Tanuj
    For refreshing Partial View use given line of code

    Step 1. Use script for calling Action for calling partial view

        <script type="text/javascript">
             function OpenPoupWindow{
                   $.post('@Url.Action("RefreshPartialView", "AdminPanel")', { 'parentid': "PassParameterValue"}, function (data) {
                            $("#PartialViewContainer").html(data);
                    });
                   }
    </script>

    Note: "OpenPoupWindow" funcation
          "RefreshPartialView" Action name
          "AdminPanel" controller name
          "PartialViewContainer" id of table or div etc, witch contain partial view for display data, like this

        <table id="Industry">
        <tr>
        <td>
                 @Html.Partial("ProductsManagerPartialView", Model.ProductsListItem)
        </td>
        </tr>
            </table>

    Step 2. Action for calling partial view

         public ActionResult RefreshPartialView(string value)
            {
               return PartialView("ProductsManagerPartialView", Model.ProductsListItem);
            }

    Note: "ProductsManagerPartialView" partial view name
          "ProductsListItem" Properties name

    i hope this will be help full for you

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!