WebImage Helper in ASP.NET MVC
ASP.NET MVC 3 provides various helper methods that are used for different purposes. WebImage helper method is one of them, which makes it very easy to display images in ASP.NET MVC. In this article, I will show you how you can use WebImage helper in ASP.NET MVC.
Open studio 2010 and create a new ASP.NET MVC 3 Web Application (Razor) project as seen below:
Choose Razor as the view engine and click OK.
Add a Controller and after adding a Controller adds the code as shown in the figure below. Also add a images folder in your which contained two images i.e. Desert.jpg and Coala.jpg.
public class HomeController : Controller
public ActionResult Index()
public void GetImage1()
WebImage wbImage = new WebImage("~/images/Desert.jpg");
wbImage.FileName = "Desert.jpg";
public void GetImage2()
WebImage wbImage = new WebImage("~/images/Koala.jpg");
wbImage.FileName = "Koala.jpg";
To get the image in a View use the following code:
<img src="@Url.Action("GetImage1")" alt="" />
<img src="@Url.Action("GetImage2")" alt="" />
The image is displayed on the page as follows:
Thank you for reading this article.