asp.net mvc - How to return to calling page, but with a slight difference, in MVC3? -
i need call mvc3 page(p2) , return calling page(p1). slight twist p2 needs call itself, referrer can end being p2.
so:
p1 - (p2 -> p2 -> p2) ->p1
so question how p1's referrer url , keep , use later go p1, regardless of number of time p2 calls itself.
i did try , populate viewbag.referrer:
<a href="@viewbag.referrer">back</a>
using following controller code, trying set on original call. viewbag.referrer seemed pick p2 referrer url, though in debug mode not resetting viewbag.referrer due isoriginalcall=0. weird. if storing pointer , not value.
public viewresult index(int id = 0, int isoriginalcall = 0) { if (isoriginalcall =1) { if (request.urlreferrer != null) { viewbag.referrer = request.urlreferrer.localpath; } } viewbag.sliid = id == 0 ? 4 : id; return view(db.stdsection.where(r=>r.inwizard).orderby(r=>r.name).tolist()); }
thoughts , solution hugely appreciated. have been going around in circles on one.
thanks in advance.
edit, attempt 2 tempdata:
calling code:
@html.actionlink("sections", "index","ssli2", new { id=item.id, returnurl = request.url.tostring() },null)
controller:
public viewresult index(string returnurl, int id = 0) { if (returnurl != "x") { //viewbag.referrer = request.urlreferrer.localpath; tempdata["referrer"] = returnurl; } viewbag.sliid = id == 0 ? 4 : id; return view(db.stdsection.where(r=>r.inwizard).orderby(r=>r.name).tolist()); }
view:
<a href="@tempdata["referrer"]">back</a>
which produces:
<a href="">back</a> when p2 goes p2, seems use p2 referrer url ????
you pass referrerurl
in p1 querystring , store value in tempdata
. survive transition 1 action call another.
another option pass referrerurl
in p1 in querystring , put value in hidden input on p2.
@html.hiddenfor(m => m.referrerurl)
or
@html.hidden("referrerurl", viewbag.referrerurl)
then pick value on each post-back , render hidden input value again.
edit
you maybe try doing like:
public viewresult index(string returnurl, int id = 0) { viewbag.returnurl = returnurl; viewbag.sliid = id == 0 ? 4 : id; // can picked in action method. tempdata["returnurl"] = returnurl; return view(db.stdsection.where(r=>r.inwizard).orderby(r=>r.name).tolist()); }
then maybe render using:
<a href="@html.raw(viewbag.returnurl)">back</a>
Comments
Post a Comment