asp.net mvc - Detect if Page was redirected from RedirectToAction() method -



asp.net mvc - Detect if Page was redirected from RedirectToAction() method -

here actionresult methods :

[httpget] public actionresult index(string cityid, string numbers, int days, bool onlyspecial) { lasttwoparameters lasttwoparameters = new lasttwoparameters(); lasttwoparameters.listcities = common.getdropdowncitieslist(); lasttwoparameters.listlasttworesult = new list<getreport_lasttwo_result>(); // if ispostback , execute if (!string.isnullorempty(cityid) && days > 0) { using (kqxs context = new kqxs()) { lasttwoparameters.listlasttworesult = context.getreport_lasttwo(cityid, numbers, days, onlyspecial).tolist(); } } homecoming view(lasttwoparameters); } [httppost]//run action method on form submission public actionresult index(list<cities> listcities, string cityid, string numbers, int days, bool onlyspecial) { homecoming redirecttoaction("index", "lasttwo", new{cityid = cityid, numbers = numbers, days = days, onlyspecial = onlyspecial}); }

what need observe if page called redirecttoaction method. because don't have need calculate result first time user open page.

there 2 ways resolve issue.

you utilize service side caching. controller has tempdata property. set tempdata["wasredirected"] = true. , after first read framework clear value. in case tempdata["wasredirected"] == null means code not redirected.

you utilize url params illustration action:

public actionresult index(bool? wasredirected) { homecoming view(); }

and in redirect method have code this:

[httppost] public actionresult redirect() { homecoming this.redirecttoaction("index", new { wasredirected = true }); }

asp.net-mvc redirect

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -