0

I am trying to modify a project so that the routes, and the parameters do not show in the URL, when you access them through an <a> element.

This is the code on the View:

@Html.ActionLink("Edit", "EditSchedule", new { id = item.OID, iorDapa = item.IOR_HORARIO }) |
@Html.ActionLink("Delete", "DeleteSchedule", new { id = item.OID, iorDapa = item.IOR_HORARIO })

I've tried to change the Action Link for a RouteLink, by calling this

 routes.MapRoute(
      name: "EditSchedule",
      url: "{controller}/{action}/{oid}_{iorDapa}",
      defaults: new { controller = "Users", action = "Index", oid = UrlParameter.Optional, iorDapa = UrlParameter.Optional }
 );

However, that didn't work, given that it keeps making a link element with an established URL, so I assume that something else is needed, perhaps some method I don't know to make a call to the api?

And... From here on I tried many things, but none seem to work.

From other projects I worked with (JS), I remember that the router called an API, which in turn called a controller file, and that controller did the logic to then call the view.

However, with this C# project I cannot get the program to call the WebApiConfig file, or the RouteConfig without actually showing the parameters on the URL.

I'm sorry If I have explained myself a tad bad, I'm a bit lost in this!

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Layan
  • 31
  • 5
  • How would you find the corresponding route with parameters if there are no parameters ? – Cid Jan 28 '20 at 11:40
  • With JS you did the same thing it was just abstracted away from you through the frontend routing – Kristóf Tóth Jan 28 '20 at 11:42
  • @Cid It's about sending them through an api, so that the route looks like this: "route/page", rather than "route/page/oid=241&iorDapa=23" – Layan Jan 28 '20 at 11:46
  • @KristófTóth I cannot remember well, but yes, it was done with Vue.JS, and there was a router in the frontend. Thing is I'm sure there's gotta be a way to send parameters forward into pages by JSON or something, calling some controller or API, I'm just lost as to how. – Layan Jan 28 '20 at 11:48
  • You can either use headers or the contents of the request if you dont want to read them from the url. Read more about parameter binding here: https://learn.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api – Kristóf Tóth Jan 28 '20 at 11:58
  • What is the **rendered** HTML of the `` element? – Dai Jan 28 '20 at 21:08
  • Set HttpContext value in the controller that renders links with routes. Get those values in the controller that renders actual route https://stackoverflow.com/a/1458444/437393 – Anonymous Jan 28 '20 at 21:21

1 Answers1

1

From ActionLink data will be send using GET method and call data will be visible in the browser address bar. To hide what you are sending, use POST method. For example post your data by submitting form or placing AJAX call to the server with POST data

Yuri
  • 2,820
  • 4
  • 28
  • 40