vendredi 18 août 2017

Why aren't my links taking me into my controller?

I guess I don't completely understand how urls work with C# projects, in the sense that I don't know how to specify a url to go through the controller and not just return a aspx page.

Say I am trying to get to my project's Index page through a Controller named "ScholarshipController.cs". I would think to hit the Index method/action in this controller, my url would be as follows (my app's name is "TuitionAssistance" fyi):

http://localhost/TuitionAssistance/Scholarship/Index

However, running this url just returns the aspx page named "Index.aspx" located in the "Scholarship" view file without hitting the Controller. Why is this happening, and how do I get it to go through the controller so the Index page, when loaded, will have the appropriate information loaded onto it.

Sorry if this is a dumb question. Any insight would be appreciated. Thanks!

Route.config:

using System.Web.Mvc;
using System.Web.Routing;

namespace ScholarshipTuitionAssistance
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            /* Scholarship */

            /* Scholarship */
            //routes.MapRoute("TuitionAssistance",
            //    "tuition/{name}",
            //    new { controller = "TuitionAssistance", action = "Index", name = "" });

            routes.MapRoute(
                name: "TuitionAssistance",
                url: "{controller}/{action}/{employee_number}",
                defaults: new { controller = "Home", action = "TuitionAssistance", employee_number = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Scholarship",
                url: "{controller}/{action}/{employee_number}",
                defaults: new { controller = "Home", action = "Scholarship", employee_number = UrlParameter.Optional }

            );

            routes.MapRoute(
                name: "Details",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Scholarship", action = "Details", id = UrlParameter.Optional }
            );

        }
    }
}




Aucun commentaire:

Enregistrer un commentaire