Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

RedirectToAction: add fragment support #3988

Closed
Bartmax opened this issue Jan 25, 2016 · 11 comments
Closed

RedirectToAction: add fragment support #3988

Bartmax opened this issue Jan 25, 2016 · 11 comments

Comments

@Bartmax
Copy link

Bartmax commented Jan 25, 2016

I can't find a way to use RedirectToAction using a fragment.

I tried:

 RedirectToAction(nameof(Index), new { fragment= "contact-message" });

with no success, looking at source code I couldn't identity if this feature exists or not.

This works, but is kind of verbose:

var localUrl = Url.Action(nameof(Index), controller: null, values: null, protocol: null, host: null, fragment: "contact-message");
return new LocalRedirectResult(localUrl);
@Eilon
Copy link
Member

Eilon commented Jan 25, 2016

@Bartmax yup that's pretty much the way to do it. Certainly back in the day sending a fragment never made sense in a redirect because that's a server concept, and fragments are a client concept.

Is the scenario here that you want to send the fragment to a client library to later process something?

@Eilon Eilon added this to the Backlog milestone Jan 25, 2016
@Bartmax
Copy link
Author

Bartmax commented Jan 26, 2016

I'm using it in a simplier scenario (non client-side). So, I don't agree with the never makes sense ;)

I have a contact us form, after filling all fields and posting a welcome message appears "thanks for contacting us" on the same page.
This is done via client side, but as good practice I always fallback to server behavior. The form is in the middle of the page and the "thanks message" appears where the form was before the post. Without the fragment the message would be off-screen on lots of devices. I use the fragment to make the browser scroll to the desired position. Redirect is because I'm using PRG pattern.

Is more like "plain-old" html use case here.

I'm not sure if I was describing the scenario clear enough. Let me know if that helps.

@Eilon
Copy link
Member

Eilon commented Jan 26, 2016

@Bartmax thanks that makes sense.

@rynowak
Copy link
Member

rynowak commented Jan 27, 2016

This would be easy to add. UrlActionContext and UrlHelper already have the plumbing to process it.

@vincez
Copy link

vincez commented Jan 30, 2016

+1

@danroth27 danroth27 added the up-for-grabs Members of our awesome commnity can handle this issue label Aug 17, 2016
@juunas11
Copy link
Contributor

juunas11 commented Nov 5, 2016

What if the action being redirected to has a parameter called fragment? If we take fragment from the route values and make it the fragment, wouldn't it essentially block this scenario:

public IActionResult MyAction(string fragment){}

@Eilon
Copy link
Member

Eilon commented Nov 7, 2016

@juunas11 that's right, so we probably wouldn't use a special fragment token like that, but instead add an explicit parameter.

@Eilon Eilon modified the milestones: 1.2.0, Backlog Nov 18, 2016
@Eilon
Copy link
Member

Eilon commented Nov 18, 2016

@dougbu assigning this bug to you because I assigned the associated PR to you as well.

@Eilon Eilon changed the title Question: RedirectToAction with fragment. RedirectToAction: add fragment support Nov 18, 2016
@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

1dd1d49

@dougbu dougbu closed this as completed Dec 6, 2016
@dougbu dougbu added 3 - Done and removed 2 - Working up-for-grabs Members of our awesome commnity can handle this issue labels Dec 6, 2016
@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

Thanks very much @juunas11 !

@Bartmax
Copy link
Author

Bartmax commented Dec 6, 2016

woot! amazing, thanks @juunas11 !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants