Hi
How to hide Url parameter in ASP.Net MVC5 when click any button i want to display main url only i dont want display related page with parameters can any one please help for this.
Hi
How to hide Url parameter in ASP.Net MVC5 when click any button i want to display main url only i dont want display related page with parameters can any one please help for this.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted Dec 26, 2023, 10:47 AM
In ASP.Net MVC5, you can hide URL parameters by using various techniques. One common approach is to use the
POSTmethod instead of theGETmethod when submitting form data. By doing so, the parameters will be sent in the request body instead of being appended to the URL.Here's an example of how you can achieve this:
In this example, the form is submitted using the
POSTmethod and the form data is sent to theActionNamemethod in the specified controller. After processing the form data, you can redirect the user to a success page using theRedirectToActionmethod.By using the
POSTmethod, the URL will only display the main URL without any parameters. However, please note that this approach may not be suitable for all scenarios, especially when you need to share or bookmark specific URLs.Jignesh KumarPosted Dec 26, 2023, 5:39 AM
Hello Thulsiram,
You can do it in couple of ways to hide parameter,
https://www.aspsnippets.com/questions/133099/Remove-Hide-QueryString-from-Url-in-ASPNet-MVC/#google_vignette
Subarta RayPosted Dec 26, 2023, 5:37 AM
Hi Thulasiram,
By following below principles you can achieve a clean and user-friendly experience without exposing parameters in the URL when a button is clicked in ASP.NET MVC.
Use POST Requests: Ensure that the action you want to perform when clicking the button is decorated with the
[HttpPost]attribute. This way, the action will only respond to POST requests, and the parameters won't be visible in the URL.Redirect After Processing: If the button click triggers some processing on the server, consider redirecting to another action using
RedirectToAction. This will change the URL in the browser, and only the URL for the new action will be visible.HTML Form: If the button is part of a form, make sure the form is set to use the POST method (
FormMethod.Post). This ensures that the form data is submitted in the body of the HTTP request rather than in the URL.Update Views Accordingly: Adjust your views and actions based on the POST approach. For example, you might have one action to display a form (HTTP GET), and another action to handle the form submission (HTTP POST). The latter action can then redirect to another action if needed.