Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6326375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:04:41+00:00 2026-05-24T17:04:41+00:00

I have a controller method as below to send an image to a MVC

  • 0

I have a controller method as below to send an image to a MVC view to display

public FileResult ShowImage(GuidID)

{

DataServiceClient client = new DataServiceClient ();

 AdviserImage result;

result = client.GetAdviserImage(ID);


return File(result.Image, "image/jpg"  );

}

in my view I am using

<img src="<%= Url.Action("ShowImage", "Adviser", new { ID = Model.AdviserID }) %>" alt="<%:Model.LicenceNumber %>" />

to display the image

but some ids does not have a image and returning null, I want to check the file result is null withing the view and if its null not not to display the image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:04:42+00:00Added an answer on May 24, 2026 at 5:04 pm

    You will need another, separate controller action that checks the datastore and returns ContentResult which will be either true or false (or some other string you want to tell whether an ID has the bytes or not) and then in the view you will need this:

    if(@Html.Action("action", "controller").ToString().Equals("true", StringComparison.OrdinalIgnoreCase)){
    // render image tag with the call to the other action that returns FileResult
    }
    

    The other option is that you have a view model which contains a reference to the image bytes. That way you prepare the model for the view (the parent model) in the controller and pull the bytes for the image there, then in the view you would have:

    if(Model.ImageBytes.Length() > 0) {
    ... do something
    }
    

    with ImageBytes property being of type byte[]

    For instance, this is a snippet from one of my views:

    @model pending.Models.Section
    @if (Model != null && Model.Image != null && Model.Image.ImageBytes.Count() > 0)
    {
        <a href="@Model.Url" rel="@Model.Rel">
            <img title="@Model.Title" alt="@Model.Title" src="@Url.Action(MVC.Section.Actions.Image(Model.Id))" /></a>
    }
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly standard .Net MVC Controller method: public ActionResult Add(Customer cust) {
I have a controller method with the following signature: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateValues(int id,
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
i have a quetion about MVC routing. I have a controller method that is
I have a controller with an action method as follows: public class InventoryController :
I have controller method in my MVC application that I am calling using the
I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{
I have my attend method below currently in my controller. My question is how
How to send triimed data using $.get() see code snippet below: $(#txtSearch).keyup(function() { $.get(/controller/method/,
I have a requirment to invoke a controller method from the view page. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.