Firstly thanks for taking the time to look at my problem.
I have a ASP.net MVC3 website in which we are using Razor.
Within this website we have a page which display a grid in a partial view.
<div id="tradeList">
@{ @Html.Partial("~/Views/Trade/TradeGrid.cshtml", Model.TradeList); }
</div>
on the main page I've added some javaScript to check if the grid requires updating and then update it if neccessary and this is working nicely.
However when you then move to page 2 of the grid after the update, the partial page is being displayed full screen rather than within it's parent view. I've noticed the url's for the page links update after the refresh, any ideas on how this can be avoided.
Partial View below
@model HRM.Models.Trades
@{
var grid = new WebGrid(Model.RecapTradeModelList, canPage: true, rowsPerPage: Model.PageSize);
}
@grid.Table(columns: columns, tableStyle: "standardtable", htmlAttributes: new { id="tradeGridID" })
@{
string sRowCount;
if (grid.TotalRowCount == 0)
{
sRowCount = "No trades found";
}
else if (grid.TotalRowCount == 1)
{
sRowCount = "1 trade found";
}
else
{
sRowCount = Convert.ToString(@grid.TotalRowCount) + " trades found.";
}
if (grid.TotalRowCount > 1)
{
int iStart;
int iEnd;
iStart = (grid.RowsPerPage * grid.PageIndex) + 1;
iEnd = (grid.RowsPerPage * (grid.PageIndex + 1));
sRowCount += " Showing " + Convert.ToString(iStart) + " to " + Convert.ToString(iEnd) + ".";
}
}
<div id="pager">@grid.Pager(mode: WebGridPagerModes.All, numericLinksCount: 7)</div>
<div id="rowcount">
@sRowCount Display
<select name="pageSize" onchange="this.form.submit();">
<option value="5" @(Model.PageSize == 5 ? "Selected" : "")>5</option>
<option value="10" @(Model.PageSize == 10 ? "Selected" : "")>10</option>
<option value="20" @(Model.PageSize == 20 ? "Selected" : "")>20</option>
<option value="25" @(Model.PageSize == 25 ? "Selected" : "")>25</option>
<option value="50" @(Model.PageSize == 50 ? "Selected" : "")>50</option>
</select>
rows per page.
</div>
Partial View Controller
public PartialViewResult TradeGrid(int pageSize = 0, string filterPeriod = "")
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
string userRole = _UserRepository.GetUserRoleByUserName(User.Identity.Name);
Trades model = new Trades();
model.PageSize = pageSize;
model.RecapTradeModelList = _TradeRepository.GetRecapTrades(User.Identity.Name, userRole, filterPeriod);
model.WebGridColumns = GenerateGridColumns();
return PartialView(model);
}
JavaScript refreshing the partial view.
if (updateRequired == "True")
{
//$('#tradeList').load('/Trade/TradeGrid?filterPeriod='+fp+'&pageSize='+@(Model.TradeList.PageSize));
jQuery.ajax({
url: "/Trade/TradeGrid",
data: { filterPeriod: fp, pageSize: @(Model.TradeList.PageSize)},
contentType: "application/html; charset=utf-8",
type: "GET",
dataType: "html",
success : function(data){
$('#tradeList').html(data);
}
})
}
Any suggestions on how I can change this behaviour would be most appreciated. Thanks in advance.