Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an Image button in MVC 4

How do you create a plain old image button in MVC 4 (Razor)? I'm looking for something like this enter image description here

like image 324
Swifty Avatar asked Jul 12 '13 08:07

Swifty


People also ask

How to add image on button in c#?

The Image property of a Button control is used to set a button background as an image. The Image property needs an Image object. The Image class has a static method called FromFile that takes an image file name with full path and creates an Image object. You can also align image and text.

How do I make an image a button in HTML?

The image buttons in the HTML document can be created by using the type attribute of an <input> element. Image buttons also perform the same function as submit buttons, but the only difference between them is that you can keep the image of your choice as a button.


2 Answers

try this

 @using (Html.BeginForm("ActionTaken", "TestController"))   {
      <button name="button" value="ActionOne" class="button" style="width: 200px;">
         <img src=""/></button>
      <button name="button" class="button" style="width: 160px;" value="ActionTwo">
      <img src=""/></button>             }
like image 199
shamcs Avatar answered Sep 19 '22 20:09

shamcs


Add this to your razor view:

<input type="image" src="<image path here>" alt="Submit" width="48" height="48">
like image 38
Alexandr Mihalciuc Avatar answered Sep 17 '22 20:09

Alexandr Mihalciuc