我正在开发一个MVC 3 Razor应用程序,当我点击浏览器中的后退按钮时,我遇到了问题。我的申请工作流程:
我正在使用VS2010和ASP.NET开发服务器,IE9作为默认浏览器。我已将OutputCache属性添加到控制器中的每个ActionResult。
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
这是我在PartialView构建的WebGrid中的链接
grid.Column(header: "",
format: @<text><a href="@Url.Action("Edit", "BuildingModels", new { @id = item.FACInventoriesId })"><img src="@Url.Content("~/Content/images/edit.png")"
alt='Edit' title='Edit' border='0'/></a></text>)
当编辑建筑物时单击后退按钮时,如何让浏览器显示WebGrid(步骤2)?还有任何想法,当我点击后退按钮时,为什么缺少CSS格式?
这是控制器代码:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ViewResult Index()
{
ViewBag.Systems = buildingsVM.GetSystemsList();
return View();
}
[HttpPost]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult GetFacilityDetails(int systemId, string facilityId)
{
try
{
ViewBag.Systems = buildingsVM.GetSystemsList();
var facility = buildingsVM.GetFacilityDetails(systemId, facilityId);
facility.Buildings = buildingsVM.GetFacilityBuildings(systemId, facilityId);
var bldgsHtml = ViewsUtility.RenderPartialViewToString(this, "_Buildings", facility.Buildings);
TempData["CurrentFacility"] = facility;
return Json(new { ok = true, facdata = facility, bldgs = bldgsHtml, message = "ok" });
}
catch (Exception ex)
{
return Json(new { ok = false, message = ex.Message });
}
}
[HttpPost]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult GetSystemFacilities(int systemId)
{
try
{
var facilities = buildingsVM.GetFacilitesBySystemId(systemId);
return Json(new { ok = true, data = facilities, message = "ok" });
}
catch (Exception ex)
{
return Json(new { ok = false, message = ex.Message });
}
}
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult Edit(int id)
{
var facility = TempData["CurrentFacility"] as FacilityModel;
return View(buildingsVM.GetBuilding(id));
}
部分视图中的代码:
@model IEnumerable<COPSPlanningWeb.Models.BuildingModel>
<!-- Current Buildings from partial view -->
@{
if (Model != null && Model.Count() > 0)
{
var grid = new WebGrid(rowsPerPage: 50, defaultSort: "BuildingNumber"); //ajaxUpdateContainerId: "tabs-2",
grid.Bind(Model, rowCount: Model.Count(), autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(
tableStyle: "webgridDisplay",
alternatingRowStyle: "alt",
columns: grid.Columns(
//grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { EmployeeID = item.EmployeeID, ContactID = item.ContactID })),
grid.Column("BuildingNumber", header: "Building Number", style: "webgridDisplayCenter"),
grid.Column("ConstructionDate", header: "Construction Date", format: @<text>@item.ConstructionDate.ToString("MM/dd/yyyy")</text>),
grid.Column("ExtSquareFeet", header: "Exterior Sq. Ft.", format: (item) => string.Format("{0:n0}", item.ExtSquareFeet)),
grid.Column("IntSquareFeet", header: "Interior Sq. Ft.", format: (item) => string.Format("{0:n0}", item.IntSquareFeet)),
grid.Column("IU_Avail", header: "IU Available"),
grid.Column("SpaceAvail", header: "Space Available"),
grid.Column("FixedAssetValue", header: "Fixed Asset Value", format: (item) => string.Format("{0:C}", item.FixedAssetValue)),
grid.Column("FixedEquipValue", header: "Fixed Equipment Value", format: (item) => string.Format("{0:C}", item.FixedEquipValue)),
grid.Column(header: "",
format: @<text><a href="@Url.Action("Edit", "BuildingModels", new { @id = item.FACInventoriesId })"><img src="@Url.Content("~/Content/images/edit.png")"
alt='Edit' title='Edit' border='0'/></a></text>),
grid.Column(header: "",
format: @<text><a href="@Url.Action("Delete", "BuildingModels", new { @id = item.FACInventoriesId })"><img src="@Url.Content("~/Content/images/trash.png")"
alt='Delete' title='Delete' border='0'/></a></text>)
))
}
}
编辑视图中的代码:
@model COPSPlanningWeb.Models.BuildingModel
@{
ViewBag.Title = "Add/Edit Inventory";
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<table style="width: 100%;" class="display">
@Html.HiddenFor(model => model.FacilityId)
@Html.HiddenFor(model => model.FACInventoriesId)
<tr>
<th colspan="2" style="text-align: left;">
Building Information - Edit Inventory
</th>
</tr>
<tr>
<td class="fieldlabel">
Facility Name
</td>
<td class="fielddata">
</td>
</tr>
<tr>
<td class="fieldlabel">
Building Number
</td>
<td class="fielddata">
@Html.EditorFor(model => model.BuildingNumber)
@Html.ValidationMessageFor(model => model.BuildingNumber)
</td>
</tr>
<tr>
<td class="fieldlabel">
Construction Date
</td>
<td class="fielddata">
@Html.EditorFor(model => model.ConstructionDate, "DateTime")
@Html.ValidationMessageFor(model => model.ConstructionDate)
</td>
</tr>
<tr>
<td class="fieldlabel">
Exterior Sq. Ft.
</td>
<td class="fielddata">
@Html.EditorFor(model => model.ExtSquareFeet)
@Html.ValidationMessageFor(model => model.ExtSquareFeet)
</td>
</tr>
<tr>
<td class="fieldlabel">
Interior Sq. Ft.
</td>
<td class="fielddata">
@Html.EditorFor(model => model.IntSquareFeet)
@Html.ValidationMessageFor(model => model.IntSquareFeet)
</td>
</tr>
<tr>
<td class="fieldlabel">
IU Available
</td>
<td class="fielddata">
@Html.EditorFor(model => model.IU_Avail)
@Html.ValidationMessageFor(model => model.IU_Avail)
</td>
</tr>
<tr>
<td class="fieldlabel">
Space Available
</td>
<td class="fielddata">
@Html.EditorFor(model => model.SpaceAvail)
@Html.ValidationMessageFor(model => model.SpaceAvail)
</td>
</tr>
<tr>
<td class="fieldlabel">
Fixed Asset Value
</td>
<td class="fielddata">
@Html.EditorFor(model => model.FixedAssetValue)
@Html.ValidationMessageFor(model => model.FixedAssetValue)
</td>
</tr>
<tr>
<td class="fieldlabel">
Fixed Equipment Value
</td>
<td class="fielddata">
@Html.EditorFor(model => model.FixedEquipValue)
@Html.ValidationMessageFor(model => model.FixedEquipValue)
</td>
</tr>
<tr>
<td class="fieldlabel">
Total Fixed Asset Value
</td>
<td class="fielddata">
@Html.EditorFor(model => model.TotalFixedAssetValue)
@Html.ValidationMessageFor(model => model.TotalFixedAssetValue)
</td>
</tr>
<tr>
<td class="fieldlabel">
Total Fixed Equipment Value
</td>
<td class="fielddata">
@Html.EditorFor(model => model.TotalFixedEquipValue)
@Html.ValidationMessageFor(model => model.TotalFixedEquipValue)
</td>
</tr>
<tr>
<td colspan="2">
<table class="display" style="text-align: center;">
<tr>
<td>
@Html.ActionLink("Add/Edit Spaces", "Index")
</td>
<td>
<input type="submit" value="Save Changes" class="button" />
</td>
<td>
@Html.ActionLink("Back to Buildings List", "Index")
</td>
</tr>
</table>
</td>
</tr>
</table>
}
当我从编辑视图中单击后退按钮时,我希望再次看到WebGrid(构建列表),但我得到的第一个视图没有任何CSS格式。
感谢Luis,我能够解决CSS格式问题,但是当我点击后退按钮时,我仍然没有看到WebGrid。我正在使用JSON填充WebGrid这可能是问题吗?我是否应该在选择下拉列表中的项目后使用表单帖子?
答案 0 :(得分:3)
类似的事情发生在我为内联网制作应用程序...但是他们欢呼起来,至少你的公司使用IE9 ......我不得不创造奇迹试图用JQuery与IE7一起制作MVC3 Razor应用程序..
现在好了,重要的是,我对IE的缓存有类似的问题,看来这个浏览器的缓存与普通新时代的浏览器“不同”,你可以试试这个:
按F12并转到标签Cache
并检查Always refresh from server
然后检查一切是否正常,如果有,请告诉网络管理员为将要使用这个新应用的所有IE浏览器制定新策略。
同时检查此https://superuser.com/questions/81182/how-to-force-internet-explorer-ie-to-really-reload-the-page
希望它有所帮助!
答案 1 :(得分:0)
您需要将属性添加到属性以使其与IE9一起使用
[OutputCache(Location = OutputCacheLocation.ServerAndClient, NoStore = true, Duration = 0, VaryByParam = "None")]