MVC - 部分视图保持显示相同的内容
我目前正在创建一个 MVC 应用程序,它基本上只是一个用于数据库内容的大型 CRUD 工具。 对于用于限制某些选择(国家、类别等)的小表,我创建了 1 个页面来加载请求的表并允许用户仅使用 Ajax 调用来添加/删除/编辑属性。
加载页面时,用户会获得包含所有表名的下拉列表。提交后,将触发以下代码:
public PartialViewResult OpenConfig(string SelectID)
{
using (DBconnection db = new DBconnection())
{
switch (SelectID)
{
case "---":
return null;
case "1":
var countries = (from x in db.tbl_CountriesSet select x).ToList();
return PartialView("Countries", countries);
case "2":
var supplierstatus = (from x in db.tbl_SupplierStatusSet select x).ToList();
return PartialView("Supplierstatus", supplierstatus);
case "3": .....
}
}
}
这就是有趣的地方。假设我打开“国家/地区”窗口,它加载正确,我可以添加/编辑/删除一个国家/地区。这些条目使用 jQuery 在页面上更新,同时使用 Ajax 调用来更新数据库。这两个工作都很好,数据库和页面都更新了。我可以继续工作,所有更改都会反映在页面和数据库中,重新加载部分视图时会出现问题。
当我在下拉列表中选择“国家/地区”值并再次提交时,程序只是跳过上面显示的方法,并显示与我第一次请求列表时显示的相同的部分视图。 我在方法中设置了一个断点,如果我加载了在触发之前尚未加载的内容,但不是我已经请求的页面。 在 Firefox 中,此方法有效并且部分视图已更新(并且触发了断点),但在 Internet Explorer 中,我的控制器完全被忽略,它一直显示相同的页面(即使我转到完全不同的页面然后返回)到设置页面)。
谁能告诉我如何告诉 IE 显式重新加载包含当前数据库内容的部分视图?
I am currently in the process of creating an MVC application, it's basically just a big CRUD-tool for database contents.
For the small tables that are used to limit some choices (countries, categories, things like that) I have created 1 page that loads the requested table and allows the user to add/delete/edit the properties using only Ajax calls.
When the page is loaded, the user gets a dropdownlist with all tablenames. When submitted, the following code is triggered:
public PartialViewResult OpenConfig(string SelectID)
{
using (DBconnection db = new DBconnection())
{
switch (SelectID)
{
case "---":
return null;
case "1":
var countries = (from x in db.tbl_CountriesSet select x).ToList();
return PartialView("Countries", countries);
case "2":
var supplierstatus = (from x in db.tbl_SupplierStatusSet select x).ToList();
return PartialView("Supplierstatus", supplierstatus);
case "3": .....
}
}
}
Here's where it gets interesting. Suppose I open the Countries window, it loads correctly, I am able to add/edit/delete a country. These entries are updated on the page using jQuery, and concurrently an Ajax call is used to updated the database. Both of these work fine, both the database is updated and the page. I can keep working and all changes are reflected in both the page and the db, the issues starts when reloading the partial view.
When I select the Countries value in the dropdownlist and submit it again, the program just skips the method shown above and displays the same partial view it showed me when I first requested the list.
I set a breakpoint in the method, if I load something I haven't loaded before it gets triggered, but not for pages I already requested.
In Firefox, this works and the partial view is updated (and the breakpoint is triggered), but in Internet Explorer, my controller is completely ignored ans it keeps displaying the same page (even when I go to a completely different page and then go back to the settings page).
Can anyone tell me how I can tell IE to explicitly reload the partial view containing the current database contents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是浏览器缓存起作用的。它返回您缓存的结果。
使用将当前日期值添加到 url 来允许从 Web 服务器加载新结果:
It's browser caching works. It returns you cached results.
Use adding current date value to url to allow loading new results from web server:
除了控制器功能之外,请尝试:
On top of your controller functions, try: