There are a few ways to refresh a partial view in ASP.NET Core 6 / MVC:
Using Ajax: You can use Ajax to make a request to the server and update the partial view without refreshing the entire page. You can create an action method that returns the partial view and use JavaScript to call this method and update the HTML on the page.
Using jQuery.load(): You can use the jQuery.load() method to load the partial view content into a container on the page. When you need to refresh the partial view, you can simply call this method again and replace the content in the container.
Using ASP.NET Core's built-in tag helpers: ASP.NET Core has built-in tag helpers that can be used to render partial views. You can use these tag helpers to render the partial view and then update the container with JavaScript when needed. To refresh the partial view, you can simply call the tag helper again.
Here is an example of using the Ajax approach to refresh a partial view:
public IActionResult GetPartialView()
{
return PartialView("_MyPartialView");
}
<div id="partialViewContainer"></div>
<script>
$(document).ready(function() {
$.ajax({
url: "@Url.Action("GetPartialView")",
type: "GET",
success: function(result) {
$('#partialViewContainer').html(result);
}
});
});
</script>
<script>
function refreshPartialView() {
$.ajax({
url: "@Url.Action("GetPartialView")",
type: "GET",
success: function(result) {
$('#partialViewContainer').html(result);
}
});
}
</script>
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-02 08:32:50 +0000
Seen: 16 times
Last updated: May 02 '23
What is the process for generating a dynamic subdomain/URL using vue.js?
How can the style of the loader be modified while the form submission is being processed?
I'm attempting to develop a Javascript-based comments section for my website.
What are some feasible methods to enable MIDI file playback on a web browser?
How can I resolve the issue of being unable to use Fetch to POST an array of Selected Checkboxes?
What is the method to hide the scroll button when reaching the bottom?
What is the process of using a custom nunjucks filter to filter collections in an eleventy template?
What is the method to create a dynamic checkbox using API data?
How can the user id from the login object be utilized in the resolvers after logging in?