0

How to use Input button for @Html.ActionLink?

In my cshtml I have this code:

<div>
  @Html.ActionLink("Back to menu", "HomeController")
</div>

Now I whant to use instead hyperlink button (Back to menu), input submit button, so this button:

<input class="btn" type="submit" value="Back to menu">

Thanks.

3 Answers 3

2

You can't - you can use css so the link will look like button, or you can utilize Url.Action and javascript instead. I.E.:

<input class="btn" type="submit" value="Back to menu" onclick="window.location='@Url.Action("Index", "Home")';return false" />
Sign up to request clarification or add additional context in comments.

3 Comments

Between '@Url.Action("Registration", "LoginController")'; shows Syntax error and return false underline with red color. If I remove qutes ' ' return false become ok (blue), but then ..tion=@ underline equal (=) and shows syntax error...
I'm not sure in what context you used that (for example I don't have semicolon - ';' at the end).
I write like this: <input type="button" value="Back to Edit Menu" onclick="window.location = @Url.Action("Registracija", "LoginAdmin"); return false"/> inside = shows Syntax error
0

Ok, I solved it, Ondrej Svejdar thanks for advice, I use javascript and works fine:

<input class="someCss" type="button" value="Back to Edit Menu" onclick="Redirect()"/>

And under button I use this javascript:

<script type="text/javascript">
    function Redirect() {
        var url = "@Url.Action("Registration")";
        location.href = url;
    }
</script>

So result is:

enter image description here

Comments

0

<input type="button" value="Button" />

value="button" />

2 Comments

Doesn't provide a solution for the problem at hand.
Code blocks on their own are not usually useful answers. Please explain what the code you're showing does, and why/how that code answers the question.

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.