How to return the view result of another action in the same asp.net core mvc controller
asp.net-core, asp.net-core-mvc
Solution
You have to specify the name of the view explicitly. So the last line would be:
return View(nameof(Show), question);
Problem
I would like to show the result of the `Show` method below from `ShowById` but I get `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); } ```