c# - MVC controller being loaded multiple times -
my goal:
the user session keep track of guid's stored in session.add(guid.tostring()).
when partial refreshed inside div, controller check existing guids. let me track notifications need displayed, being displayed avoid duplicates ..etc.
the problem:
when notification should displayed again, isn't though see in model being passed view
what think cause
for reason when debug controller start of method load partial, it's being loaded many times believe why when notification should displayed, isn't.
main index view refreshes partial. #overview. interval every 15 seconds.
function intervaltrigger() { $('#overview').load('/home/overview'); }; <div id="overview"> @{html.renderpartial("overview", "home");} </div>
code inside overview partial displays alerts
@for (int = 0; < model.displayalerts.count(); i++) { @:$(function () { @:$.notify({ @:keepopen: true, @:caption: '@model.displayalerts[i].sectionname', @:content: '@model.displayalerts[i].paramdescription <br/> @model.displayalerts[i].detaildatetime.tostring("mm/dd/yyyy hh:mm:ss tt ")', @:type: 'alert' @:}); @:}); }
code populating model being handed view
overviewmodel model = new informationcontroller().getoverviewmodel(); model.displayalerts = new list<basicsectiondetailmodel>(); list<basicsectiondetailmodel> details = new collector.infocollector().getsectiondetailsnotokstate(); list<guid> sessionkeys = new list<guid>(); (int = 0; < session.contents.count; i++) { guid guid; if (guid.tryparse(session.keys[i].tostring(), out guid)) { sessionkeys.add(guid); } } list<basicsectiondetailmodel> addalert = details.where(x => !sessionkeys.any(x2 => x2 == x.id)).tolist(); foreach (basicsectiondetailmodel alert in addalert) { session.add(alert.id.tostring(), null); } list<guid> removealert = sessionkeys.where(x => !details.any(x2 => x2.id == x)).tolist(); foreach (guid remove in removealert) { session.remove(remove.tostring()); } model.displayalerts = addalert; return model;
i found issue
model.displayalerts = addalert;
addalert being destroyed. had copy contents model , not assign 1 var another.
Comments
Post a Comment