Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> MVC >> WebImage Helper in ASP.NET MVC
WebImage Helper in ASP.NET MVC
WebImage Helper in ASP.NET MVC


by Rohit Kesharwani on 10/8/2011 8:38:53 PM

Views: 5393       Comments: 0

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:

WebImage Helper in ASP.NET MVC

Choose Razor as the view engine and click OK.

WebImage Helper in ASP.NET MVC

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.

using System.Web.Mvc;

using System.Web.Helpers;

 

namespace WebImageDemo.Controllers

{

    public class HomeController : Controller

    {

        public ActionResult Index()

        {

            return View();

        }

        public void GetImage1()

        {

            WebImage wbImage = new WebImage("~/images/Desert.jpg");

            wbImage.Resize(300, 300);

            wbImage.FileName = "Desert.jpg";

            wbImage.Write();

        }

        public void GetImage2()

        {

            WebImage wbImage = new WebImage("~/images/Koala.jpg");

            wbImage.Resize(300, 300);

            wbImage.FileName = "Koala.jpg";

            wbImage.Write();

        }

    }

}

 

To get the image in a View use the following code:

<html>

<head>

    <title>Index</title>

</head>

<body>

    <div>

            <img src="@Url.Action("GetImage1")" alt="" />

            <img src="@Url.Action("GetImage2")" alt="" />     

    </div>

</body>

</html>


The image is displayed on the page as follows:

WebImage Helper in ASP.NET MVC

Thank you for reading this article.

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Rohit KesharwaniRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 5625
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.