How do I solve a “view not found” exception in asp.net core mvc project

前端 未结 16 1979
梦毁少年i
梦毁少年i 2020-12-09 15:53

I\'m trying to create a ASP.NET Core MVC test app running on OSX using VS Code. I\'m getting a \'view not found\' exception when accessing the default Home/index (or any oth

16条回答
  •  旧时难觅i
    2020-12-09 16:00

    Reply to @LukaszDev (dont think I can attach images to a comment) My view is Index.cshtml, typo from my side. See attached screenshot

    My controller is as simple as can be. I get same error for both Index and Welcome

    using Microsoft.AspNetCore.Mvc;
    
    namespace app1 {
    
        [Route("[controller]")]
        public class HomeController : Controller {
    
            // default action, configured in Startup.cs route
            public IActionResult Index() {
                // handles route /home
                return View();
            }
    
            [Route("welcome")]
            public IActionResult WelcomeActionDoesNotHaveToMatchName() {
                // handles router /home/welcome
                return View("Welcome"); 
            }
        }
    }
    

提交回复
热议问题