1

i am creating a web app in mvc-5

here is my actionlink button which looks like

<p>
    <span class="btn btn-success glyphicon glyphicon-plus">
        @Html.ActionLink(" ", "insert")
    </span>
</p>

when a user clicks on this button he should be redirected to the following page

public ActionResult insert()
        {
            return View();
        }

but nothing is happening when i am clicking the button

what i need to do?

  • 1
    you need to supply parameters properly. At least, controller name, action name, and display text. please check - https://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink(v=vs.118).aspx – Nirman May 15 '17 at 12:49
  • 1
    This html with this button is inside a page rendered by the same controller (e.g within index action)? – Alisson Reinaldo Silva May 15 '17 at 12:49
  • @Alisson yes both are on the same controller –  May 15 '17 at 12:50
  • I would also watch out for ActionLink and learn the difference between Url.Action and Html.ActionLink. 99% of the time, you are going to want to use @Url.Action("ControllMethodName","ControllName") HTML.ActionLink vs Url.Action in ASP.NET Razor But the most important thing to remember in either case, "ControllerMethodFunctionNAmeHere","AwesomeCoolControllerNameHere" – Kevin B Burns May 15 '17 at 15:28

2 Answers2

3

Your link format doesn't look correct.

You've only got

 @Html.ActionLink(" ", "insert")

Add your "Link text", action and controller name and you should be ok.

@Html.ActionLink("Link Text", "YourAction", "YourController")

NOTE : There are 9 overloads for ActionLink allowing you to omit the controller (among other things )if the link target is handled by the same controller.

Hope that helps

Wheels73
  • 2,850
  • 1
  • 11
  • 20
  • OP is using [this overload](https://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink(v=vs.118).aspx#M:System.Web.Mvc.Html.LinkExtensions.ActionLink%28System.Web.Mvc.HtmlHelper,System.String,System.String%29) which has 2 parameters - the link text and the action name! –  May 15 '17 at 13:02
  • @StephenMuecke - Ah ok.. So he's got a link (No link text) with a span presumably to show a button.... So is his action not in the same controller do you think? ( Just seen your answer :) ) – Wheels73 May 15 '17 at 13:07
  • OP has confirmed its in the same controller - its just that there is nothing to click :) –  May 15 '17 at 13:08
1

Because you not generating any text in the link, there is nothing to 'click'.

Change your code to generate a link containing the <span> element

<p>
    <a href="@Url.Action("insert")">
        <span class="btn btn-success glyphicon glyphicon-plus"></span>
    </a>
</p>