Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionButton instead of ActionLink

I want to create a button which when clicked calls an action. I have used Html.ActionLink to create a link which does exactly that but there is no Html.ActionButton. Is there some other way?

like image 773
Sachin Kainth Avatar asked Jun 18 '12 10:06

Sachin Kainth


People also ask

What is difference between HTML ActionLink and URL action?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What is an ActionLink?

ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

How do I transfer my ActionLink model to my controller?

You'll have to serialize your model as a JSON string, and send that to your controller to turn into an object. Please don't format with snippets when the language used is not displayable by them. It doesn't improve the answer and makes your answer more cluttered. Regular code blocks will work fine.


2 Answers

Here is an example using Bootstrap's CSS button and applying it against the link to make it look exactly like the button.

@Html.ActionLink("Select", "Select", new { id = patient.Id }, new { @class = "btn btn-primary", @style = "color:white" }) 
like image 193
Flea Avatar answered Sep 20 '22 05:09

Flea


Is there some other way?

You could use a html <form>:

@using (Html.BeginForm("someAction", "someController")) {     <button type="submit">OK</button> } 
like image 45
Darin Dimitrov Avatar answered Sep 23 '22 05:09

Darin Dimitrov