ASP.NET Core/MVC: Adding a Button to a Razor View Page that Returns a Method On-Click
I needed to add a button in my ASP.NET Core MVC web application that on-click would start a method that would return a list of items scraped from another website.
Something like this:
The code I got to work for doing so is:
<button type="button" id="startButton"
onclick="location.href='@Url.Action('List', 'ArbitrageScraper')'">
Start Scrape
</button>
This code resides inside of the View for your controller. My button functions as a “Start” button for a web-scraping process.
The general formula for adding a button of your own is:
<button type="button" id="YOUR_BUTTONS_NAME"
onclick="location.href='@Url.Action('ACTION_METHOD_NAME',
'CONTROLLER_NAME_WHERE_THE_ACTION_METHOD_RESIDES')'">
TEXT YOU WANT TO DISPLAY ON THE BUTTON
</button>