Click here to Skip to main content
Click here to Skip to main content

Tagged as

Calling a MVC Controller and Action Method using HTML Button or Image

, 22 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
MVC 3
When creating a link to a controller action in ASP.NET MVC, using the generic ActionLink method is preferable, because it allows for strongly typed links that are refactoring friendly.
Default: ActionLink
 @Html.ActionLink("Delete", "Delete", new { id = item.ID }) 
 
However, what if we want to have an image that links to an action? You might think that you could combine the ActionLink and Image and Button helpers like this:

Using Button

<input type="button" title="Delete" value="D" onclick="location.href='@Url.Action("Delete", "movies", new { id = item.ID })'" />

Using Image

<a href="@Url.Action("Delete", "movies", new { id = item.ID })" title="Edit">
<img src="../../Content/Images/Delete.png" />
</a>
 
Thanks,
Imdadhusen

License

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

Share

About the Author

Sunasara Imdadhusen
Software Developer (Senior) Infostretch Ahmedabad-Gujarat
India India
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen
 
AWARDS:
  1. 1st Best Asp.Net article of SEP 2010
  2. 2nd Best Asp.Net article of MAY 2011
 
Read More Articles...
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 PinmemberMahsa Hassankashi17-Aug-14 11:09 
GeneralRe: My vote of 5 PinprofessionalSunasara Imdadhusen17-Aug-14 23:40 
QuestionGreat One Imdad Bhai PinmemberNIRMAL UPADHYAY6-Mar-14 19:20 
AnswerRe: Great One Imdad Bhai PinmemberSunasara Imdadhusen6-Mar-14 19:23 
QuestionNeat little bit of code PinmemberMember 1015611214-Aug-13 1:03 
AnswerRe: Neat little bit of code PinprofessionalSunasara Imdadhusen22-Apr-14 3:55 
Generalthanks Pinmemberpatelvipul_be14-Mar-13 13:49 
GeneralRe: thanks PinprofessionalSunasara Imdadhusen22-Apr-14 3:58 
QuestionWell Done PinmemberMember 925303813-Dec-12 10:21 
AnswerRe: Well Done PinprofessionalSunasara Imdadhusen22-Apr-14 3:58 
Questionhow can I pass Textbox box value on this button click Pinmembersagar wasule5-Dec-12 23:13 
AnswerRe: how can I pass Textbox box value on this button click PinprofessionalSunasara Imdadhusen22-Apr-14 3:57 
GeneralRe: how can I pass Textbox box value on this button click Pinmembersagar wasule24-Apr-14 2:04 
GeneralRe: how can I pass Textbox box value on this button click PinprofessionalSunasara Imdadhusen24-Apr-14 3:00 
GeneralMy vote of 5 PinmemberSavalia Manoj M7-Nov-12 1:13 
GeneralRe: My vote of 5 PinprofessionalSunasara Imdadhusen22-Apr-14 3:56 
Questionmy 5! Pinmemberkimberly wind15-Jun-12 18:23 
AnswerRe: my 5! PinprofessionalSunasara Imdadhusen22-Apr-14 3:59 
QuestionPOST method in action link Pinmemberkimberly wind15-Jun-12 0:45 
AnswerRe: POST method in action link PinmemberSunasara Imdadhusen15-Jun-12 3:11 
GeneralRe: POST method in action link Pinmemberkimberly wind15-Jun-12 17:52 
GeneralRe: POST method in action link PinmemberSunasara Imdadhusen15-Jun-12 18:18 
AnswerRe: POST method in action link PinmemberSunasara Imdadhusen15-Jun-12 18:19 
It will set id of Link to value of item.id from model.
 
Thanks,
Imdadhusen

sunaSaRa Imdadhusen
+91 99095 44184

GeneralRe: POST method in action link Pinmemberkimberly wind15-Jun-12 18:22 
GeneralRe: POST method in action link PinmemberSunasara Imdadhusen15-Jun-12 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141030.1 | Last Updated 22 May 2011
Article Copyright 2011 by Sunasara Imdadhusen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid