0

How can i display an image in image control whose path is stored in database. Please provide me with sample code i have get the path from database but how can i show in in image control . here is my code

   [HttpPost]
    public ActionResult DisplayPic()
    {
        string UserName=User.Identity.Name;
        var getPath = from p in Session.Query<Registration>()
                      where p.Email == UserName
                      select p.Path;
        if (getPath.Count() > 0)
        {
           //display pic???

        }

        return View();
    }

View:

     @{
        ViewBag.Title = "DisplayPic";
      }

    <h2>DisplayPic</h2>
    @using (Html.BeginForm())

   {
     <img alt="" src="" width="200" height="200" />
   }
2
  • Add a string variable to your model (say 'ImageUrl') and Commented Sep 27, 2013 at 11:48
  • This is giving me an error Cannot perform runtime binding on a null reference.How can i pass the value of ImageUrl in img src that i have get from db in DisplayPic Method. Commented Sep 27, 2013 at 12:20

1 Answer 1

2

Store image path in your model property and use

<img src="@Url.Content(Model.ImagePath)" alt = "Image" />    
Sign up to request clarification or add additional context in comments.

2 Comments

I ditnot get how it will display the profile image of a particular user.I have get the path of the image that i want to show but i how can i give that path to image src.
provide an additional property in your model class for the imagepath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.