How do I render a partialview ASP MVC

1

I have a View that has a div and inside it a partialview

EX:

<div>
     @Html.RenderPartial("MeuPartial");
</div>

No page load renders right, however, I needed it rendered every time I clicked a button.

<button class="btn btn-primary" [email protected]("MeuPartial");>Atualizar</button>

onclick does not accept the method. How do I render within div ?

    
asked by anonymous 14.04.2016 / 07:20

2 answers

0

Recently I needed to do just that and after so much searching I ended up opting to use javascript to do the job of loading partialview into div .

Javascript

       function RefreshList() {
            var url = '@Url.Action("ListProduction", "Home")';
            $.post(
            url,
            function (data) {

                $('#listproduction').html(data);

            });

        }

HTML

<a href="javascript:RefreshList();" class="btn btn-primary"><i class="fa fa-refresh">&nbsp;Atualizar</i></a>
<div id="listproduction">                    
      @Html.Partial("ListProduction")
</div>
    
14.04.2016 / 22:18
1

You can create an Action to return you to partialview, and use jQuery .load () seek and popular your partial. It would look something like this:

Action:

public PartialViewResult GetPartial()
{
    return PartialView("~/Areas/Sua_area/Views/Shared/_MeuPartial");
}

And the part in JavaScript:

$("#idSuaDiv").load('url_sua_action', function(res, status) {
  if (status == 'success') {
        //OK
  }
})
    
14.04.2016 / 13:01