In my ASP.NET MVC project i have the following situation:
An ExController with this action:
public ActionResult Index()
{
//Get Data from Repository
return View(Model);
}
In the Ex View folther i have a Index.cshtml and a _PartialIndexGrid.cshtml.
In the Index i have a ribbon menu with a checkbox, and when i click on it i would like to refresh just the grid placed on the _PartialIndex.cshtml, is it possible?
The Index View:
//Ribbon Code here
@Html.Partial("_PartialIndexGrid", Model)
<script>
if (e.parameter) {
$.ajax({
url: '@Url.Action("Index")',
type: "get",
success: function (result) {
$("_PartialIndexGrid").html(result);
},
failure: function () {
alert('error');
}
});
</script>
This script actually do the ajax request, but is not reloading the grid partial view. Thanks.
Create a container div and on checkbox change check if its checked reload the partial view via ajax call like this:
<div id="PartiaContainer">
@Html.Partial("_PartialIndexGrid", Model)
</div>
<input type="checkbox" id="checkbox1"/>
<script>
$('#checkbox1').change(function(){
if(this.checked)
{
$.ajax({
url: '@Url.Action("Index")',
type: "get",
success: function (result) {
$("#PartialContainer").html(result);
},
failure: function () {
alert('error');
}
});
}
});
</script>
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.