3

I am new to MVC and have encountered a problem. I have an HTML page that scrolls down to a section when that section's name is clicked from the navigation bar but now I have to change this HTML line of code to MVC:

<li><a class="page-scroll" href="#services">Services</a></li>

I have tried to use Html.ActionLink but have not had any success yet!

What I have so far:

@Html.ActionLink("Services", "Index", "Home", new { area = "#services" }, new { @class = "page-scroll" })
sc1234
  • 127
  • 3
  • 10
  • 1
    possible duplicate of [Including an anchor tag in an asp.net mvc Html.ActionLink](http://stackoverflow.com/questions/274586/including-an-anchor-tag-in-an-asp-net-mvc-html-actionlink) – markpsmith Apr 10 '15 at 11:26

2 Answers2

3

Create your own helper or use raw html

<li><a href="@Url.Action("Action", "Controller")#services">Link Text</a></li>

OR

<%= Html.ActionLink("Link Text", "Action", "Controller", null, null, "services", new { parameter = "example"}, null) %>

On your Index page:

<div id="services"> <p>Here is the content you want to make show when you click the link</p> </div>

When you click on 'Link Text' it will direct you to the services section of your Index page.

LazyDog
  • 317
  • 4
  • 5
-1

Try

@Html.ActionLink("Services", "Index", "Home#services", new { @class = "page-scroll" })
Bardo
  • 2,470
  • 2
  • 24
  • 42