这是我的控制器,我想调用AnswerASelect方法。
App
这是我的View在按钮单击的位置我想用模型作为参数调用AnswerASelect方法,类似于...... AnswerASelect(model)
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");
}
我希望找到一个简单的解决方案,非常感谢您提前。我是Web App开发的新手,我发现这很难学。我看过几篇类似的帖子,但我对它们并不是很了解,因此很难将解决方案应用到我当前的问题中。
答案 0 :(得分:0)
<h4 class="card-title addbutton">
<button type="button" onclick="CreateModelDialog('@Url.Action("Create", "Controller",new {restaruntId =Model.RestaurantId})')" class="btn btn-info btn-rounded m-t-10 modal-link">Add</button>
</h4>
function CreateModelDialog(url) {
debugger
$(".modal-backdrop").remove();
$('#modal-container').html("");
$(".modal-backdrop").show();
$(".stream-loader").show();
$.get(url, function (data) {
$(".stream-loader").hide();
$('#modal-container').html("");
$('#modal-container').html(data);
debugger
$('#modal-container').attr("style", "display:block !important");
});
}