I am using .NET MVC 5 to develop a web application. I have a controller with a method that takes a single parameter.
public class ProductController : Controller
{
[HttpGet]
public ActionResult Index(string ProductCode)
{
// Retrieve product details from database based on product code.
....
}
}
In my source Home.cshtml file, I have this link:
<a href="/Product/Index?ProductCode=123456">
When the user clicks on the link, the ProductController will be called, and the product details are then presented in the product view.
So far everything works fine.
The only issue I have is that when the user clicks on the link, the URL "http://..../Product?Index=ProductCode=123456" will be showing in the browser's address bar. How do I prevent the URL showing up in the address bar?
I'm guessing that I need to change the [HttpGet] attribute in ProductController.Index() to [HttpPost]. Then in the Home.cshtml file, how do I modify it to make an HTTP POST call instead of GET? I suppose I need to modify the to add an "onClick" to call a JavaScript or jQuery function.