Click here to Skip to main content
11,436,156 members (63,478 online)
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. 2nd Best Mobile Article of January 2015
  2. 3rd Best Web Dev Article of May 2014
  3. 2nd Best Asp.Net article of MAY 2011
  4. 1st Best Asp.Net article of SEP 2010

Read More Articles...
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 Pin
Mahsa Hassankashi17-Aug-14 12:09
memberMahsa Hassankashi17-Aug-14 12:09 
GeneralRe: My vote of 5 Pin
Sunasara Imdadhusen18-Aug-14 0:40
professionalSunasara Imdadhusen18-Aug-14 0:40 
QuestionGreat One Imdad Bhai Pin
NIRMAL UPADHYAY6-Mar-14 20:20
memberNIRMAL UPADHYAY6-Mar-14 20:20 
AnswerRe: Great One Imdad Bhai Pin
Sunasara Imdadhusen6-Mar-14 20:23
memberSunasara Imdadhusen6-Mar-14 20:23 
QuestionNeat little bit of code Pin
Member 1015611214-Aug-13 2:03
memberMember 1015611214-Aug-13 2:03 
AnswerRe: Neat little bit of code Pin
Sunasara Imdadhusen22-Apr-14 4:55
professionalSunasara Imdadhusen22-Apr-14 4:55 
Generalthanks Pin
patelvipul_be14-Mar-13 14:49
memberpatelvipul_be14-Mar-13 14:49 
GeneralRe: thanks Pin
Sunasara Imdadhusen22-Apr-14 4:58
professionalSunasara Imdadhusen22-Apr-14 4:58 
QuestionWell Done Pin
Member 925303813-Dec-12 11:21
memberMember 925303813-Dec-12 11:21 
AnswerRe: Well Done Pin
Sunasara Imdadhusen22-Apr-14 4:58
professionalSunasara Imdadhusen22-Apr-14 4:58 
Questionhow can I pass Textbox box value on this button click Pin
sagar wasule6-Dec-12 0:13
membersagar wasule6-Dec-12 0:13 
AnswerRe: how can I pass Textbox box value on this button click Pin
Sunasara Imdadhusen22-Apr-14 4:57
professionalSunasara Imdadhusen22-Apr-14 4:57 
GeneralRe: how can I pass Textbox box value on this button click Pin
sagar wasule24-Apr-14 3:04
membersagar wasule24-Apr-14 3:04 
GeneralRe: how can I pass Textbox box value on this button click Pin
Sunasara Imdadhusen24-Apr-14 4:00
professionalSunasara Imdadhusen24-Apr-14 4:00 
GeneralMy vote of 5 Pin
Savalia Manoj M7-Nov-12 2:13
memberSavalia Manoj M7-Nov-12 2:13 
GeneralRe: My vote of 5 Pin
Sunasara Imdadhusen22-Apr-14 4:56
professionalSunasara Imdadhusen22-Apr-14 4:56 
Questionmy 5! Pin
kimberly wind15-Jun-12 19:23
memberkimberly wind15-Jun-12 19:23 
AnswerRe: my 5! Pin
Sunasara Imdadhusen22-Apr-14 4:59
professionalSunasara Imdadhusen22-Apr-14 4:59 
QuestionPOST method in action link Pin
kimberly wind15-Jun-12 1:45
memberkimberly wind15-Jun-12 1:45 
AnswerRe: POST method in action link Pin
Sunasara Imdadhusen15-Jun-12 4:11
memberSunasara Imdadhusen15-Jun-12 4:11 
GeneralRe: POST method in action link Pin
kimberly wind15-Jun-12 18:52
memberkimberly wind15-Jun-12 18:52 
GeneralRe: POST method in action link Pin
Sunasara Imdadhusen15-Jun-12 19:18
memberSunasara Imdadhusen15-Jun-12 19:18 
AnswerRe: POST method in action link Pin
Sunasara Imdadhusen15-Jun-12 19:19
memberSunasara Imdadhusen15-Jun-12 19:19 
GeneralRe: POST method in action link Pin
kimberly wind15-Jun-12 19:22
memberkimberly wind15-Jun-12 19:22 
thanks i wants to one another thing in jquery seems ur master in everything

i want to initially hide dropdown list can u please help on that
GeneralRe: POST method in action link Pin
Sunasara Imdadhusen15-Jun-12 23:47
memberSunasara Imdadhusen15-Jun-12 23:47 
GeneralMy vote of 4 Pin
manoj kumar choubey1-Jun-12 21:27
membermanoj kumar choubey1-Jun-12 21:27 
GeneralRe: My vote of 4 Pin
Sunasara Imdadhusen22-Apr-14 4:56
professionalSunasara Imdadhusen22-Apr-14 4:56 
GeneralThanks Nirmal for your vote and appreciation. Pin
Sunasara Imdadhusen1-Aug-11 18:56
memberSunasara Imdadhusen1-Aug-11 18:56 
GeneralReason for my vote of 5 Easy to understand and very helpful Pin
NIRMAL UPADHYAY21-Jun-11 19:34
memberNIRMAL UPADHYAY21-Jun-11 19:34 
GeneralRe: Reason for my vote of 5Easy to understand and very helpful Pin
Sunasara Imdadhusen22-Apr-14 4:58
professionalSunasara Imdadhusen22-Apr-14 4:58 

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
Web04 | 2.8.150428.2 | Last Updated 22 May 2011
Article Copyright 2011 by Sunasara Imdadhusen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid