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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:20:54+00:00 2026-05-20T15:20:54+00:00

<img alt=Upload Profile Pic src=<%= ViewData[PicSource].ToString() %> /> UPDATE: Also, when we write this

  • 0
<img alt="Upload Profile Pic" src="<%= ViewData["PicSource"].ToString() %>" />

UPDATE: Also, when we write this syntax, visual studio underlines several elements of our html code with curly red lines just like when we have some syntax errors and it looks like that the syntax we have written will not work and is wrong, but actually when I built it, it worked.

It also denies to auto format the html code. This was an enough good reason for me for asking this question because even though I knew that this syntax will work, still then when everytime I write like this, I feel that I have done something wrong.

  • 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-20T15:20:54+00:00Added an answer on May 20, 2026 at 3:20 pm

    Yes, you can write like that.

    However, it is often referred to as “spaghetti code”, and the best practice would be to use a helper method.

    public static class ImageHelper
    {
        public static MvcHtmlString Image(this HtmlHelper html, string sourcePath, object htmlAttributes)
        {
            return html.Image(sourcePath, new RouteValueDictionary(htmlAttributes));
        }
        public static MvcHtmlString Image(this HtmlHelper html, string sourcePath, IDictionary<string,object> htnlAttributes)
        {
            if(string.IsNullOrEmpty(sourcePath))
            {
                throw new ArgumentException("Image source path cannot be null or empty.", "sourcePath");
            }
            TagBuilder tagBuilder = new TagBuilder("img");
            tagBuilder.MergeAttributes<string,object>(htnlAttributes);
            tagBuilder.MergeAttribute("src", sourcePath, true);
            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.SelfClosing));
        }
    }
    

    then, you’re use looks like

            Html.Image(ViewData["PicSource"] as string, new {alt = "Upload Profile Pic"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at this situation: www.websitea.com displays an img tag with a src attribute of
HTML: <div id=media-photo> <img src=/uploads/photos/16.jpg alt= /> </div> <a href=/uploads/photos/5.jpg class=img> <img src=/uploads/photos-thumbs/5.jpg alt=
For the following image html: <img src=/some.png alt=something /> In CSS, you can target
$('.icon1').mouseover(function(){ $(this).find('img').attr('src', 'recursos/botban/maq1.png'); }); Should work right? It's just an arbitrary test to see
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Is it possible to call a JavaScript function from the IMG SRC tag to
I've an image tag inside a div element. <div id = myDiv> <img alt
This doesn't work panel1.layout: layout [ offset: 0x0 yuml-image: image img ] panel2.layout: layout
I have an img tag in my webapp that uses the onload handler to
Upon a click on an IMG, I would like to get to the next

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.