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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:49:53+00:00 2026-05-11T15:49:53+00:00

I’m attempting to make a TinyURL clone in ASP.NET MVC as a learning project.

  • 0

I’m attempting to make a TinyURL clone in ASP.NET MVC as a learning project.

Right now, all I want is to be able to submit new URLs to my /Home/Create action via a form.

alt text

I have my LINQ expression all setup, I have my routing setup, and I have my view setup but something is wrong with my setup.

Routing:

 routes.MapRoute(             'Default',                                              // Route name             '',                           // URL with parameters             new { controller = 'Home', action = 'Index' }  // Parameter defaults         );   routes.MapRoute(             'Redirect',             '{hash}',             new { controller = 'Home', action = 'RequestLink', hash = '' }         ); 

These routes allow me to be able to go to my website, http://www.tinyurlclone.com/ and if nothing is passed ti will simply go to my Home/Index() action. However, if you put anything after the slash, it will consider that a Link Hash and attempt to retrieve the hash.

My HomeController is as follows:

[HandleError]   public class HomeController : Controller   {       TinyGetRepository repo = new TinyGetRepository();      public ActionResult Index()     {         return View();     }       public ActionResult Create(String url)     {         String hash = repo.addLink(url);         ViewData['LinkHash'] = hash;         return View();     }      public ActionResult RequestLink(String hash)     {         String url = repo.getLink(hash);         return Redirect(url);      } } 

My repo class has all my LINQ expressions in it for dealing with the database and I don’t really need to include them because it isn’t relevant to this question.

Finally, my basic Home/Index() view (used for submitting urls) is as follows:

<%@ Page Language='C#' Inherits='System.Web.Mvc.ViewPage' %>  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  <html xmlns='http://www.w3.org/1999/xhtml' > <head runat='server'>     <title>Index</title> </head> <body>     <div>     <center>             <span style='font-size: 14pt'>TinyGet <em>(beta)</em></span><br />             <span style='font-family: Tahoma'>Reduce your long links to smaller ones to keep them more memorable....<br />             </span>             <% using(Html.BeginForm('Create', 'Home')) %>             <% { %>             <%= Html.TextBox('url') %>             <input type='submit' name='submitButton' value='Shorten Link!' />             <% } %>        </center>     </div> </body> </html> 

However, my form simply isn’t firing any methods when I click submit.

Furthermore, if I view the source of my generated HTML I can see that it didn’t make my Form’s action correctly, it reads:

<form action='' method='post'><input id='url' name='url' type='text' value='' />             <input type='submit' name='submitButton' value='Shorten Link!' />             </form> 

Why is the HTML helper putting ” as the action when it ~should~ be putting /Home/Create? Why isn’t my /Home/Create action method being called? Even if I don’t use the Html helpers and specify the <form> tag manually it throws errors.

What is wrong here?

Source for project: here

  • 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. 2026-05-11T15:49:54+00:00Added an answer on May 11, 2026 at 3:49 pm

    The problem is that you don’t have a route that matches the route values (controller = Home, action = Create).

    You have two routes, one is the empty string (no parameters), which matches Controller = ‘Home’, Action = ‘Index’. The other is your hash route, which matches Controller = ‘Home’, Action = ‘RequestLink’. So, when ASP.Net Routing goes to build a URL from the route values you’re providing, it can’t find one (since none of them have the ‘{controller}’ and ‘{action}’ parameters).

    The simplest solution, in this case, is to create a direct route to the ‘Create’ action, so that you can still use your ‘hash’ route. Put this at the top of your RegisterRoutes method. NOTE: Order does matter! ASP.Net Routing checks each route, in the order added, until it finds a match.

    routes.MapRoute(         'Create',                                              // Route name         'Create',                           // URL with parameters         new { controller = 'Home', action = 'Create' }  // Parameter defaults     ); 

    Since you have that ‘hash’ route, you can’t really use the default ‘{controller}/{action}/{id}’ technique, since the ‘hash’ value would be consider a valid Controller name. So, if someone requested: http://www.mysite.com/fjhas82, MVC would look for a Controller called ‘fjhas82’ and complain that it couldn’t find it. Unfortunately, this means you have to manually add new routes for each new Controller Action (like I showed above), which is a pain.

    The best solution (in my opinion) is to use Regex Constraints: If your hashes have a very well-defined format (say: 5 letters followed by 2 numbers, or ‘_’ followed by any alpha-numeric characters, etc.), or if you’re willing to impose such a format, you can use the Regex constraints supported by ASP.Net Routing. Then, you’d only need these two routes

    routes.MapRoute(         'Redirect',         '{hash}',         new { controller = 'Home', action = 'RequestLink' },         new { hash = @'[a-zA-Z]{5}[0-9]{2}' } // Regex Constraints     );  routes.MapRoute(     'Default',                                              // Route name     '{controller}/{action}/{id}',                           // URL with parameters     new { controller = 'Home', action = 'Index' }  // Parameter defaults );     

    Under these routes, if MVC sees a controller name like: ‘Home’, it will check the first route, find that it doesn’t match the regular expression, and move to the next one. NOTE: My Regular Expression syntax may be a bit rusty, so I’d use something like http://regexpal.com/ to test a Regex first, to make sure it works with your hashes and controller names.

    Hope that helps, I know I wrote a lot, but MVC is so flexible, you can do things in so many different ways!

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at this similar post for answers. Make… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer On my own GFX card the maximum resolution for an… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer Just use static folder configured as virtual folder in IIS.… May 12, 2026 at 1:11 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.