Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:13:23+00:00 2026-06-04T20:13:23+00:00

I am creating a project in MVC3 along with C# for a local college.

  • 0

I am creating a project in MVC3 along with C# for a local college. The requirement was to show teacher profile when something like http://www.mysite.com/teachercode is entered in browser.

I have made a method ShowTeacher in my Teacher controller class. My Plan is to lookup database on application start and for every teacher register the same route as shown below, which will handle the request further, is this approach correct?

foreach(Teacher tch in TeacherCollection)
routes.MapRoute(
            "Teacher route" + tch.Id,
            tch.TeacherCode,
            new { controller = "Teacher", action = "ShowTeacher" }
        );

Secondly if a new teacher is added in database, is it possible to add the route as soon as teacher is saved?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:13:25+00:00Added an answer on June 4, 2026 at 8:13 pm

    You don’t need to add a route at runtime, instead you can set up a route that will catch URLs of the form http://www.mysite.com/teachercode, so long as none of your teachercodes have the same name as any of your controllers.

    In RegisterRoutes, add another route (which needs to be the first one), which will route queries to the ShowTeacher action method of your TeacherController, along with a route constraint.

    routes.MapRoute(
        "Teacher route", // route name
        "{teacherCode}", // url
        new { controller = "Teacher", action = "ShowTeacher" }, // defaults
        new { teacherCode = @"[A-Za-z]{1,10}" } // constraints
        );
    

    The constraint in this example – @"[A-Za-z]{1,10}" – is speciying that the teachercode will contain only upper or lowercase letters, and is between 1 and 10 characters long. You can adapt this to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a project from the book Sanderson Pro ASp.net mvc3. But I have
When creating a new project for MVC3 I have an option to select a
I'm creating a new project, asp.net mvc3 with Razor, and wanting to turn the
I'm looking at creating my first ASP.NET MVC application using MVC3. The project template
In an MVC3 project, i use an Html.BeginForm to post some (model-)values. Along with
When creating a standard MVC 3 project there is an EntityFramework.dll and .xml file
When creating a project with the webapp archetype in Maven, they subtly advise not
I am creating a project that only uses client side languages. I want to
When I'm creating new project with GWT plug in it creates a skeleton project
I'm creating a project to house an iPhone library for common code for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.