简体   繁体   中英

Refresh view component .net core RC2

I have one normal view with two views components inside. Normal view have also a button and the both views components have a button too.

How i can refresh the views components after clicking on button from normal view? And how i can refresh second view component after clicking on botton from first view component?

I already tryed to find a way, but without success!

Best regards

Ultimately view components generate HTML markup when razor executes that code. If you want to update some part of your HTML page ( like a partial page update ), you may consider using jQuery and ajax to do that.

Something like this.

$(function(){

   $("#SomeButton").click(function(e){

     e.preventDefault();
     //make the ajax call and get new data/markup for the
     //  div rendered by your first view component and update it      
     var url="TheUrlToActionMethodWhichReturnsPartialMarkup";
     $("#DivIdA").load(url);
   });

});

You can do the same thing for updating other parts of your page ( markup generated by view component 2) as well. Update the url to an action method which returns a partial view result.

I tried this:


`$("#buttonrefresh").on("click", function () {`
    `$.ajax({`
        `type: "GET",`
        `url: '@Url.Action("VCTest")'`
    `(function (result) {`
        `$("#show").html(result);`
    `});`
`});`

This script is to refresh one view component after clicking on button from normal view. VCTest is the name of the view component. show is the name of the div where the view component is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM