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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:39:42+00:00 2026-06-17T18:39:42+00:00

I have a complicated route that I would like to match with an HtmlHelper.BeginForm

  • 0

I have a complicated route that I would like to match with an HtmlHelper.BeginForm method. I’ve read quite a few articles and answers on using route value dictionaries and object initializers and html attributes. But they all fall short of what I want to do…

Here is the route I want to match:

// Attempt to consolidate all Profile controller actions into one route
routes.MapRoute(
    "Profile",
    "{adminUserCode}/{controller}s/{customerId}/{action}/{profileId}",
    new { adminUserCode = UrlParameter.Optional, controller = "Profile"},
    new { adminUserCode = @"\d+", customerId = @"\d+", profileId = @"\d+" }
);

An example url for the controller & action I want to match with this would be:

http://mysite.com/123/Profiles/456/UpdatePhoneNumber/789

With the actual phone number being in the POST body

And here is the closest syntax I’ve come to getting right:

@using (Html.BeginForm(
    "UpdatePhoneNumber",
    "Profile",
    new {
        customerId = Model.LeadProfile.CustomerId,
        profileId = Model.CustomerLeadProfileId
    }))
{
    <!-- the form -->
}

But this puts the parameters in the object as query string parameters, like this:

<form method="post"
    action="/mvc/123/Profiles/UpdatePhoneNumber?customerId=78293&profileId=1604750">

I just tried this syntax on a whim, but it output the same thing as the other overload

@using (Html.BeginForm(new
{
    controller = "Profile",
    customerId = Model.LeadProfile.CustomerId,
    action = "UpdatePhoneNumber",
    profileId = Model.CustomerLeadProfileId
}))

I know I can just fall back on raw HTML here, but there seems like there should be a way to get the silly HtmlHelper to match more than the most basic of routes.

  • 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-17T18:39:43+00:00Added an answer on June 17, 2026 at 6:39 pm

    If you want to use complicated routes in your form you need to use the BeginRouteForm Method

    @using (Html.BeginRouteForm("Profile", new
    {
        controller = "Profile",
        customerId = Model.LeadProfile.CustomerId,
        action = "UpdatePhoneNumber",
        profileId = Model.CustomerLeadProfileId
    }))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a route: Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>'); I would like to route this url to
I have a complicated report that I need to draw with GDI+ (I don't
I have this complicated slider that utilizes tons of animation. I'm trying to find
Im having a very strange problem, i have a complicated view that returns incorrect
I have a very complicated site built on CSS3 that has html elements 3d-transformed,
I know that this question has been asked quite a few times, but I
I have a pretty common case for nested routes, I feel like, that looks
For complicated reasons I won't go into, we have some requests that come into
I have a complicated problem and I hope to explain it clearly possible... I
I have a complicated MySQL query which takes a lot of time, selecting from

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.