Home > DeveloperSection > Forums > Refresh partial view in mvc4
Tanuj Kumar

Total Post:134

Points:940
Posted on    November-16-2012 4:07 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 3514  View(s)
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


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    November-17-2012 12:49 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick