I need to call a same view on button click. Actually i need to refresh a view on button click.
You can try like below:
Controller:
public class PartialController : Controller
{
public IActionResult PartialViewFromButtonClick()
{
return PartialView("_PartialViewFromBtnClick");
}
}
Partial View Sample:
<h4>Load Partial View</h4>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<div>
<table class="table-bordered ">
<tr>
<td><strong>Search</strong></td>
<td>
<input type="text" name="searchkey" class="form-control" placeholder="Enter Search Key" />
</td>
<td>
<input type="submit" value="Search" style="font-weight: bold;" />
</td>
</tr>
</table>
</div>
<br />
The View Where You Like To Load The Partial View:
HTML:
<div>
<button id="btnLoadPartialView" class="btn btn-primary">Load Partial View</button>
</div>
<div id="loadPartailView">
</div>
Script:
@section scripts {
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function () {
$("#btnLoadPartialView").click(function () {
$("#loadPartailView").load("/Partial/PartialViewFromButtonClick");
});
});
</script>
}
Output:
Note: If you would like to laod partial view with parameter you could try like this
$('#loadPartailView').load('/PartialController/PartialViewFromButtonClick?parameter=2095');Additionally each time when you would load the partial view in this fashion it will autometically refresh thepartial viewitself. No additional things to implement.
Hope it would help you.