我想从Show
显示以下ShowById
方法的结果,但我得到InvalidOperationException: The view 'ShowById' was not found
public async Task<IActionResult> ShowById(int id)
{
Expression<Func<Question, bool>> findById = (q) => q.QuestionId == id;
return await this.Show(findById);
}
private async Task<IActionResult> Show(
Expression<Func<Question, bool>> predExp)
{
var question = await _context.Questions
.Where(predExp)
.FirstOrDefaultAsync();
if (question == null) {
return NotFound();
}
question.Topics = await (
from topic in _context.Topics
join qtopic in _context.QuestionTopics on topic.TopicId equals qtopic.TopicId
where qtopic.QuestionId == question.QuestionId
select topic
).ToListAsync();
question.Answers = await _context.Answers
.Where(a => a.QuestionId == question.QuestionId)
.ToListAsync();
return View(question);
}
答案 0 :(得分:4)
您必须明确指定视图的名称。所以最后一行是:
return View(nameof(Show), question);