Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC - Partial view keeps displaying the same content

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?

like image 448
Flater Avatar asked Apr 07 '26 06:04

Flater


1 Answers

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:

$('#container').load("http://mysite/myview/?" + new Date().getTime(), function () { });
like image 158
Samich Avatar answered Apr 08 '26 19:04

Samich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!