I have an action in which I want to intercept any possible integer id that comes and place it behind a hash. (I have some Javascript that is handling the id). I am only doing this extra step for the sake of URL-hackers like me who might forget my convention of putting a hash before the id.
Here is my action:
public ActionResult Edit(int? id)
{
if (id != null) return Redirect(Url.Action("Edit") + "/#" + id);
return View();
}
The problem is that the Url.Action method is preserving the passed id. Url.Action("Edit") is returning "{controller}/Edit/{id}". I want it to just return "{controller}/Edit"! (And my code is tacking on an additional "/#{id}").
For example, a request to this URL:
http://localhost:2471/Events/Edit/22
is redirecting to this URL:
http://localhost:2471/Events/Edit/22/#22
when I want it to redirect to this URL:
http://localhost:2471/Events/Edit/#22
I'm frustrated. Does anyone know how to get a URL to the current action that doesn't include the passed id?