This is my Controller, where I would like to call the method AnswerASelect.
namespace VotingWebApp.Controllers
{
public class HomeController : Controller
{
public async Task<IActionResult> Home()
{
return View(await _context.QuestionItem.ToListAsync());
}
public async Task<IActionResult> Answer(int? id)
{
if (id == null)
{
return NotFound();
}
var questionItem = await _context.QuestionItem.SingleOrDefaultAsync(m => m.ID == id);
if (questionItem == null)
{
return NotFound();
}
return View(questionItem);
}
public async Task<IActionResult> AnswerASelect(int? id)
{
var questionItem = await _context.QuestionItem.SingleOrDefaultAsync(m => m.ID == id);
questionItem.AnswerAVote = questionItem.AnswerAVote + 1;
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
This is my View where on the button click I would like to call the AnswerASelect method with the model as the parameter, something like... AnswerASelect(model)
@model VotingWebApp.Models.QuestionItem
@{
ViewData["Title"] = "Answer Question";
}
<h2>@Html.DisplayFor(model => model.Question)</h2>
<div class="container">
<button type="button" class="btn btn-info btn-lg" onclick= "CALL AnswerASelect(Model)">@Html.DisplayFor(model => model.AnswerA)</button>
I was hoping to find a simple solution, thank you very much in advance. I'm new to Web App development and I am finding this difficult to learn. I have seen a few posts similar but I don't really have a good understanding of them, making it hard to apply the solution to my current problem.