1

I want to use MVC to load only a few pages, an index.cshtml and a few error views. The index page will contain only a <div ng-view></div> and the app will only use one MVC controller. With my current set up everything seems to work fine until an Angular route attempts to a view, when that occurs I get either a 500 or a 404 depending on how I point to the html. Do I need to make an MVC ActionResult for every view I try to load? I was hoping to avoid that.

Here's an example MVC Controller.

    public ActionResult Index(string code)
    {
        try
        {
            var model = new CodeContainer();

            if (string.IsNullOrWhiteSpace(code))
                return InvalidLink();

            model = ValidateCode(code);

            if (model.IsExpired)
            {
                return ExpiredView();
            }
            if (!model.IsValid || model.PatientID == -1)
            {
                return InvalidView();
            }
            else
            {
                return View();
            }
        }
        catch (Exception ex)
        {
            // handle error
        }

        return InvalidView();            
    }

Here is how my Angular routing is set up using ngRoute.

careNotify.config(function ($routeProvider) {
    $routeProvider.when('/', {
        controller: 'MainController',
        templateUrl: 'Views/splash.html'
    }).when('/login', {
        controller: 'loginController',
        templateUrl: 'Views/Account/login.html'
    })
});

Content of splash.html

<div class="home-splash">
    <div class="home-overlay">
        <div class="container">
                <div class="logo-box">
                    <img src="images/cn-logo-splash.png">
                </div>
            </div>
            <div class="main-content-footer">
                <p>Powered by <img src="images/health-grid-logo-1.png"></p>
            </div>
        </div>
    </div>   

the index page will load into the RenderBody() in the _layout.cshtml as expected, yet when it tries to load the splash.html view a 500 shows in the console. Switching to ../Views/splash.html will cause a 404 instead.

Stavros_S
  • 2,145
  • 7
  • 31
  • 75
  • Maybe, you should post the content of `splash.html` page... – ADreNaLiNe-DJ Mar 24 '16 at 13:15
  • 1
    Possible duplicate of [How do you request static .html files under the ~/Views folder in ASP.NET MVC?](http://stackoverflow.com/questions/17949460/how-do-you-request-static-html-files-under-the-views-folder-in-asp-net-mvc) – David Mar 24 '16 at 13:19
  • @ADreNaLiNe-DJ Edit made to add the content of the page. It's just some static html. – Stavros_S Mar 24 '16 at 13:21

0 Answers0