0

I've been assigned to rewrite some existing ASP.NET pages using MVC. Prior to working on this assignment I was completely uneducated on MVC.

The pages I'm working on are simple reports that accept parameters from the user, pass the parameters to a stored procedure (SQL Server) and return a set of data which is displayed on a web page.

Prior to my arrival on this project a previous team member had been in the process of converting these pages to MVC. He left before I arrived. Now I have been assigned to continue the task of converting these pages to MVC.

I've worked through some MVC tutorials on W3schools and Channel 9, and those made sense to me. I was able to get those simple tutorial apps up and running without any trouble. But I'm having a whole lot of trouble converting these 'real' pages to MVC.

I say "converting", but what I mean by that is that I'm leaving the existing pages alone and building a new MVC "page" that mimics the behavior of the existing page.

I've been working under the assumption that I could create a new controller, then build a new view off of the new controller, then run my application and navigate to the new view by typing it's associated URL into the browser's address bar. But when I try this I get a 404 error.

No one else on my team is familiar enough with MVC to give me any kind of advice. I have no idea how to troubleshoot this situation. I'll provide as much specific information as I can about the project I'm working on, I'm just not sure what details to provide at the moment.

So in summary, what I'm asking for right now is some help on how to create a new view in this existing application and how to get the application to successfully display the view when I attempt to navigate to it's URL.

Thanks.

Edit:

I've started out with a very simple controller, just to see if I could get the application to display its associated view. The controller isn't meant to do anything other than display its associated view. Here's the code for it:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.Mvc;  

namespace TSS.Controllers  
{  
    public class Tim_Dev_Controller : Controller. 
    {  
        //  
        // GET: /Tim_Dev_/  

        public ActionResult Index()  
        {  
            return View();  
        }  

        public ActionResult Test()  
        {  
            return View();  
        }  

    }  
}  

Edit 1.1: Here's code for the corresponding view:

@{

ViewBag.Title = "Index";

Layout = "~/Views/Shared/_Layout.cshtml";

}

<h2>Index</h2>

Edit 2: Here's the contents of the routeconfig.cs file:

    using System.Web.Mvc;

using System.Web.Routing;

using TSS.Utilities;

namespace TSS

{

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(

name: "Default",

url: "{instance}/{controller}.aspx/{action}/{id}",

defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

);

routes.MapRoute(

name: "CTPCatalogImportEmployee",

url: "{instance}/{controller}.aspx/{action}/{empId}/{series}"

);
}
}
}

Edit 3: Here's a little more information. I can place a break point in the existing controllers where they call

return View()

and hit those break points when I open those pages. But when I place a breakpoint at the same

return View()

call in my new controller it never gets hit. (This is when I try to navigate to my new view by entering the associated URL into the address bar of the browser. )

10
  • 2
    Please post some controller code and the corresponding view and we'll be able to help. Commented Mar 23, 2016 at 16:57
  • 1
    Please post code that you have and tried so that we can assist in the best way that we can! Commented Mar 23, 2016 at 16:58
  • will this help? davepaquette.com/archive/2013/12/30/… Commented Mar 23, 2016 at 17:07
  • maybe creating a view with an iframe displaying the old web forms page :) Commented Mar 23, 2016 at 17:12
  • Generally speaking, a 404 when you expect something to be there is a routing issue. If attribute routing is being used, you may need to add Route attributes to your controller/actions. Otherwise, post the content of your RouteConfig.cs file. Commented Mar 23, 2016 at 17:28

2 Answers 2

1

You should ignore the old aspx files, and keep the routes without .aspx

public static void RegisterRoutes(RouteCollection routes) {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{instance}/{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

    routes.MapRoute(
        name: "CTPCatalogImportEmployee",
        url: "{instance}/{controller}/{action}/{empId}/{series}"
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

I replaced the contents of my RegisterRoutes() method with your suggested code, but to no avail. I still can't bring up my new view when I enter it's URL.
0

Occasionally I have a tendency to overlook the obvious. I never bothered to rebuild my solution after adding the new controller and view. Once I did that the controller fired and pulled up the view without any trouble.

[sigh]

Thanks everyone, for your help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.