c# - List View (index controller) does not update after an individual record has been edited -
i have mvc app multiple controllers reading/writing to/from ms sql database, , want consolidate database calls 1 controller (called xyzdataset.cs) instead of making calls db individual methods in each controller.
the situation is: when edit individual record, upon successful database update, i'm redirected index() method list of records displayed.
with scenario 1 (below), index() view displays updated list, freshly updated values.
with scenario 2, index() view not display freshly updated values; however, when go record edited, see newest values - so, database gets updated.
what culprit? have tried using both [outputcache(duration = 0)] , [outputcacheattribute(varybyparam = "*", duration = 0, nostore = true)] on controller , method level, not change outcome.
thanks hints on solution!
/*** items controller ***/ // scenario 1 - works charm, displays updated list in view after record has been updated: public actionresult index() { var itemlist = db.entityobj.include(i => i.status).orderbydescending(i => i.itemid); return view(itemlist.tolist()); } // scenario 2 - not display freshly made record edits, though changes recorded in db: public actionresult index() { var itemlist = xyzdataset.getlist("a"); return view(itemlist.tolist()); } namespace appspace.dal { public class xyzdataset { private static mvctestsdbentities db = new mvctestsdbentities(); public static list<itemxyz> getlist(string viewtype) { list<itemxyz> itemlist = new list<itemxyz>(); switch (viewtype.tolower()) { case "p": itemlist = db.entityobj.include(i => i.status).where(i=>i.statusid == 999).orderbydescending(i => i.itemid); break; case "a": itemlist = db.entityobj.include(i => i.status).orderbydescending(i => i.itemid); break; default: itemlist = db.entityobj.include(i => i.status).where(i=>i.statusid == 999).orderbydescending(i => i.itemid); break; } return itemlist; } }
}
Comments
Post a Comment