Reputation: 23
How to get the value of an input button in an ASP.NET Core MVC controller?
This is my html code in the view
<html>
<body>
<form asp-controller="Home" asp-action="GetstartTime" method="post" id="TableF">
<input id="1" name="f1" form="TableF" class="btn btn-primary" type="submit" value="12:00 PM"/>
<input id="2" name="f2" form="TableF" class="btn btn-primary" type="submit" value="2:00 PM"/>
<input id="3" name="f3" form="TableF" class="btn btn-primary" type="submit" value="3:00 PM"/>
</form>
</body>
</html>
Upvotes: 2
Views: 4304
Reputation: 413
in the razor :
<form asp-controller="Controller" asp-action="PostData">
<input id="f0" name="f0" form="TableF" class="btn btn-primary" type="submit" value="12:00 PM"/>
</form>
in the controller :
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> PostData(string f0)
{
var buttonvalue =f0;
}
Upvotes: 5