I have a page which load data from multiple partial views. One of the partial view has few links. say 3. Every time user clicks on the link I reload the page with a data related to clicked link. The form looks like this.
@model TestPostback.Models.HomeModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<form id="testform" method="post" action="@Url.Action("Index","Home")" runat="server">
<div>
<table>
<tr>
<td>
<a href="@Url.Content("/Home/Index?selectedValue=Personal")"> This is a test page </a>
</td>
</tr>
</table>
</div>
</form>
<div>
<table>
<tr>
<td style="vertical-align:top;">
<h2 class="expand">Test Expand</h2>
<div class="collapse">
<table id="testgrid" class="scroll" cellpadding="0" cellspacing="0"></table>
</div>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
jQuery(document).ready(function () {
var grid = jQuery("#testgrid");
grid.jqGrid({
url: 'Home/GridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', 'Votes', 'Title'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left' },
{ name: 'Votes', index: 'Votes', width: 40, align: 'left' },
{ name: 'Title', index: 'Title', width: 400, align: 'left'}
],
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '',
caption: 'My first grid'
});
});
</script>
Controller Code :-
public ActionResult Index(string selectedValue)
{
return View();
}
public JsonResult GridData(string sidx, string sord, int page, int rows)
{
int totalPages = 1; // we'll implement later
int pageSize = rows;
int totalRecords = 3; // implement later
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = new[]{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
}
};
return Json(jsonData);
}
Here is what I am trying to do. When i click on Link "This is a Test Page", it calls the controller with some value but it does not load my grid. I want that value because i want to load a grid with different value based on user clicks. what are the changes I have to make for this to work?
please advice.