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

  • SEARCH
  • Home
  • 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 3284206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:07:43+00:00 2026-05-17T20:07:43+00:00

I have a view called Associations that has a drop down list and a

  • 0

I have a view called Associations that has a drop down list and a button. When the user selects an option and presses submit, I want them to go to Association/{associationKey}. Association needs to work on get and post.

Currently, with the code below, when the form is posted, it DOES go to Association and displays the correct record, BUT it does not append the associationKey to the url.

So I am getting:

http://localhost/Association

instead of:

http://localhost/Association/202

If I manually navigate to http://localhost/Association/202 everything works perfectly, so get and post are both working fine….I just want the key in the url after a post!

Surely there must be something super simple I am doing wrong. Relevant code below.

Thanks!

ASSOCIATIONS view:

<% Html.BeginForm("Association", "Staff", FormMethod.Post); %>
<%:Html.DropDownList("associationKey", new SelectList(Model.Associations.ToList(), "AssociationKey", "LegalName"))%>
<input type="submit" value="Edit The Selected Record" />
<% Html.EndForm(); %>

STAFF controller:


        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        public ActionResult Association(int associationKey)
        {
            return View("Association", new AssociationViewModel(associationKey));
        }

GLOBAL.asax:


        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("Default", "{action}", new { controller = "Staff", action = "Default" });
            routes.MapRoute("Associations", "Associations", new { controller = "Staff", action = "Associations" });
            routes.MapRoute("Association", "Association/{associationKey}", new { controller = "Staff", action = "Association" });
        }

ASSOCIATION view model:


    public class AssociationViewModel
    {

        public Repository db = new Repository();

        public Association Association {get; private set; }

        public List TelephoneTypes { get; private set; }

        public AssociationViewModel(int associationKey)
        {
            Association = db.AssociationById(associationKey);
            TelephoneTypes = db.ListTelephoneTypes().ToList();
        }

    }
  • 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-05-17T20:07:43+00:00Added an answer on May 17, 2026 at 8:07 pm

    I think you should separate out your controller actions into a Get action and a POST action like so:

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Association(int associationKey)
    {
        return View("Association", new AssociationViewModel(associationKey));
    }
    
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Association(AssociationViewModel model)
    {
        return RedirectToAction("Association", new {associationKey= model.associationKey});
    }
    

    The MVC framework will automatically bind the selected value from your SelectList to the model (assuming you have a property in the model to hold the selected value). From there you just need to redirect to your GET method passing in the key.

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

Sidebar

Related Questions

Let's say I have a page view called PagePreview.aspx . on that page I've
I have created a view called business this runs sucessfully ,but the problem is
I have a view in my Django application that automatically creates an image using
I am developing a module to display video. I have created a view so-called
Probably a simple question but I haven't found a solution. I have several view
I want to change the background color of a custom view. I have a
I have a view hierarchy like this: nav1 (UINavigationController, top level object in nib)
I have a table Item (ItemId int PK, Title vc, Description vc) I created
I have Rails 3 application (running Rails RC1), and I have the following controller:
I just started learning Drupal and I'm having a heck of a time displaying

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.