1

I'm on working an Asp.net MVC project that I have use an URL like that:

<a href="@Url.Action("Index","Privacy")#Legal" target="_blank">Terms and Conditions</a>

Which I want it go to: /Privacy/Index#Legal But it auto added the slash which make the URL not good: /Privacy/Index#/Legal

What I'm wrong? Sorry I'm a new Asp.net MVC developer. Thanks

UPDATED: I found the problem that my project used AngularJS, the solution that config the $locationPrivider will solve the problem:

$locationProvider.html5Mode({
    enabled: true,
    requireBase: false,
    rewriteLinks: false
});

Thanks for all your support.

7
  • why don't you just provide the url to href? Commented Aug 17, 2016 at 5:21
  • Thank you for your quick reply, I also use the normal URL but it also have problem. Commented Aug 17, 2016 at 5:26
  • what problem? you are just providing the correct url. Commented Aug 17, 2016 at 5:29
  • The problem was that I want it go to the "Legal" section on the page. If the url correct is "/Privacy/Index#Legal" it wil work. If the URL is "/Privacy/Index#/Legal" it won't work. Commented Aug 17, 2016 at 5:36
  • <a href = "/Privacy/Index#Legal">Terms and condition</a>. Whats the problem with this? Commented Aug 17, 2016 at 5:50

1 Answer 1

3

You can configure whether or not to use trailing slash in urls throug AppendTrailingSlash property of RouteCollection object. In order to remove it from all URLs in your application you should modify RegisterRoutes method

public class RouteConfig
 {
        public static void RegisterRoutes(RouteCollection routes)
        {
            ///add this line
            routes.AppendTrailingSlash = false;
        }
 }

Once you set this up @Url.Action("Index","Privacy") will be generated without trailing slash

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.