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 6987927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:00:09+00:00 2026-05-27T19:00:09+00:00

In my view I use the following code to get an image from my

  • 0

In my view I use the following code to get an image from my database (through an action method) and display it in a html tag

<img src="@Url.Action("DownloadBackground", new { projectID = 31 })" />

The Action method named DownloadBackground return a FileContentResult with the image stored in my DB. It works but I would like to create a helper method to replace it.

I would like something like:

@Html.BackgroundFor(31) 

Where 31 is the id of the project I need. I would like this helper method to produce the same html code.

So I try to create my helper like this:

public static MvcHtmlString BackgroundFor(this HtmlHelper helper, int id)
{
    // What code here ?? 

    var builder = new TagBuilder("a");
    builder.MergeAttribute("src", ???);
    return new MvcHtmlString(builder.ToString(TagRenderMode.SelfClosing));
}
  • 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-27T19:00:10+00:00Added an answer on May 27, 2026 at 7:00 pm

    Try this:

    builder.MergeAttribute("src", new UrlHelper(helper.ViewContext.RequestContext)
                                        .Action("DownloadBackground",
                                                new { projectID = id }));
    

    or, you can use

    new UrlHelper(((MvcHandler)HttpContext.Current.Handler).RequestContext)
    

    This would do too

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

Sidebar

Related Questions

I use the following code to load an image into an scroll view. The
I use the following code to display a tooltip <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False DataKeyNames=ID
I want to use coverflow view in my app. To get the reflection image
I use the following code all the time in my view controller: UIView *view
Question is should i use properties for my view controllers? Consider the following case:
I use the MFC list control in report view with grid lines to display
I'm having problems implementing an asynchronous image loader to the following code. I read
I am going through the following tutorial . I need to get thumbnail images
I am trying to use the ImageLoader class from libs-for-android (http://code.google.com/p/libs-for-android/), and am getting
i use the following code in my jqgrid colmodel: cellattr: function (rowId, tv, rawObject,

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.