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

  • Home
  • SEARCH
  • 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 8832699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:35:38+00:00 2026-06-14T08:35:38+00:00

I got a strange errror. My html helper is supose to render html for

  • 0

I got a strange errror. My html helper is supose to render html for a menu, simple ul’s and li’s. now the problem becomes that it starts to render a tags around other elements. The string returned from the html is correct, it seems something after that is causing the problem. I just cant figure out why. So i thought maybe a fresh pair of eys could spot it.

method

public static MvcHtmlString TopMenuLinks(this HtmlHelper helper, List<IMenuItemNodeViewData> menuItem)
        {
            if (menuItem != null && menuItem.Count > 0)
            {
                var count = 0;
                var resultString = "";

                var ulTag = new TagBuilder("ul");

                foreach (var item in menuItem.Where(x => x.IsVisibleInMenu))
                {
                    count++;
                    var liTag = new TagBuilder("li")
                                    {
                                        InnerHtml = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{1}\" />{2}", item.URL, "/Content/images/image.png", item.Name)
                                    };

                    ulTag.InnerHtml += liTag.ToString();

                    if (count % 3 == 0 || count == menuItem.Where(x => x.IsVisibleInMenu).Count())
                    {
                        resultString += ulTag.ToString(TagRenderMode.Normal);
                        ulTag = new TagBuilder("ul");
                    }
                }

                return MvcHtmlString.Create(resultString);
            }

            return null;
        }

partialview

<div class="top-columns link-container">

        <div class="links">

            <%= Html.TopMenuLinks(Model.MenuItems) %>

        </div>

    </div>

    <div class="top-columns icons">

        <div class="icons-contain">
            <img src="/Content/images/image.png" alt="image" />
        </div>

    </div>

It renders the following

<div class="links">
    <ul>
        <li>..</li>
        <li>..</li>
        <li>..</li>
    </ul>
    <ul>
        <li>..</li>
        <li>..</li>
    </ul>
    <a href="url"></a>
</div>

<a href="url"></a>
</div>
<a href="url">

    <div class="top-columns icons">

        <div class="icons-contain">
        </div>

</a>
</div>
<a href="url"></a>

It suppose to be

<div class="links">
    <ul>
        <li>..</li>
        <li>..</li>
        <li>..</li>
    </ul>
    <ul>
        <li>..</li>
        <li>..</li>
    </ul>
</div>
<div class="top-columns icons">

        <div class="icons-contain">
        </div>
</div>
  • 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-06-14T08:35:39+00:00Added an answer on June 14, 2026 at 8:35 am

    you forgot to close <a> tag in the following line :

      InnerHtml = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{1}\" />{2}", item.URL, "/Content/images/image.png", item.Name)
    

    try this :

     InnerHtml = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{1}\" />{2} </a>", item.URL, "/Content/images/image.png", item.Name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a really simple class that is giving a strange error. The class
I have got a strange problem.This is my code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I've got an app that hosts simple html pages for people. Some of whom
Got a strange problem created a little stored proc which need to execute a
I got a strange problem. I have a tabcontrol and 3 tabs. On every
i've met a strange behaviour in Firefox with this simple script: <html> <head> <script
after adding the OCMock framework i got that strange error... :( ld: file not
I have got this strange problem.XSL is not working with xml.This is my xml
I'm trying to parse html with BeautifulSoup and got strange error. Here's the minimal
I've got a strange issue with a simple select dropdown not displaying in IE8.

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.