Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The markup is this (in _Layout.cshtml):

<button type="button" class="btn btn-default">@Html.ActionLink("Home", "Index", "Home")</button

But when I click on the button, nothing happens (the browser doesn't even try to load a different page.)

If I change it to this:

<button type="button" class="btn btn-default" onclick="location.href='@Url.Action("About", "Home")'">About</button>

It works, but of course loses some styling (the text color is black instead of blue). I'll figure that out myself.

Kornfeld Eliyahu Peter 9-Nov-14 12:32pm
ActionLink renders an a tag (anchor), however while wrapped inside a button the button 'eats' the click so a never got clicked...
Marc Clifton 10-Nov-14 8:53am
That's what I figured -- I must have mangled something when I was looking at some examples of how to do fancy buttons with Bootstrap and then incorrectly folded it into the existing Razor code the VS produces as a startup template.
Afzaal Ahmad Zeeshan 9-Nov-14 13:17pm
I'll figure that out myself. Not a good way to ask question. :-)
Kornfeld Eliyahu Peter 9-Nov-14 13:20pm
But he will even so...Believe him...
Afzaal Ahmad Zeeshan 9-Nov-14 13:22pm
Yeah, he is the Protector.
Kornfeld Eliyahu Peter 9-Nov-14 13:40pm
He much more than that...and long before...

I agree, if ActionLink is used why there is any need to add button tag. If there is a need to have button style, then only
@Html.ActionLink("Home", "Index", "Home",new{@class="Name"})

add a class that has the css for a similar looking button, else the second approach does the job Sir.
Thanks. :)
I ended up changing the code to this:

<button type="button" class="btn btn-default btn-topbar" onclick="location.href='@Url.Action("Index", "Home")'">Home</button

So I could stick with the CSS that Bootstrap uses.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900