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 8331295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:22:30+00:00 2026-06-09T02:22:30+00:00

I am in the process of learning MVC 3 using the basic project template

  • 0

I am in the process of learning MVC 3 using the basic project template coupled with several examples I have. Things are going well, but now I am trying to implement my controllers and I am having a couple of issues.

So far I have modified the _Layout.cshtml file to have a new link with a specified route defined:

     <header>
        <div id="title">
            <h1>My MVC Application</h1>
        </div>
        <div id="logindisplay">
            @Html.Partial("_LogOnPartial")
        </div>
        <nav>
            <ul id="menu">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.RouteLink("Contracts", "Contract")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
            </ul>
        </nav>
    </header>

and my global.asax.cs file is as follows:

        routes.MapRoute(
            "Contract",
            "Contract",
            new { controller = "Contract", action = "List", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

This works fine as in it returns the expected action view from my Contract controller.

However I would like to modify this to accept an id into the List action. I know that I need to change the List method to accept a parameter, no problem there, but the issue it with the route and how to pass this paramter into the List method from the RouteLink in the _Layout.cshtml file. I have tried a few things, but this bit is really stumping me.

I intend to pass an id from the User that I logged in as through the AccountController, however I will ask another question about that to keep this more consise.

Thank you very much.

  • 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-09T02:22:32+00:00Added an answer on June 9, 2026 at 2:22 am

    You don’t actually need your Contract route, as your Default route will work for any controller and action that corresponds to the pattern controller/action/(optional id parameter here). See the comment in the template actually says Parameter defaults. This means, if there is no Controller, Action, or id passed in, it will default to those values. That’s why you can just browse to the root of the website and the Home controller’s Index action is the default call.

    When using routes, you need to remember that the route parameter names need to match the parameter names in your actions.. for example, your Default route currently lets you do this:

    [HttpGet]
    public ActionResult MyAction(int id) {
    
    }
    

    But, if you changed your default route to be this:

    routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{myIDParameter}", // URL with parameters
            new { controller = "Home", action = "Index", myIDParameter = UrlParameter.Optional } // Parameter defaults
        );
    

    ..your Index action would no longer bind the integer parameter properly.. you would have to change the action to this:

    [HttpGet]
    public ActionResult MyAction(int myIDParameter) {
    
    }
    

    In answer to your question, it might make more sense to use an ActionLink, like the other two you already have:

    @Html.ActionLink("Contracts", "Contract", "ActionMethodHere", new { id = UserIdHere }, null)
    

    That assumes though, that you remove your Contract route and just use the default route.

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

Sidebar

Related Questions

I have been learning .MVC recently and am having trouble understanding how to process
I am learning asp.net MVC, as I have been using the sqlconnection, sqlcommands etc
I am working on building a lightweight MVC, mainly for the learning process but
I'm in the process of learning Databases and SQL. From what I have read
I'm in the process of learning C++. But there's so much more that I
I am in the process of learning the Yii Framework. I have been following
I am in the process of learning to unit test. I have a 'domain
I'm currently in the process of learning ASP MVC and am running into a
I am in the process of learning ASP.NET MVC and I am learning it
I'm in the process of learning JQuery, and I'm looking to have a list

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.