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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:37:35+00:00 2026-05-12T09:37:35+00:00

I have this foreach (var columnName in columns) { writer.RenderBeginTag(HtmlTextWriterTag.A); writer.AddAttribute(href, null); writer.Write(Delete); writer.RenderEndTag();

  • 0

I have this

foreach (var columnName in columns)
{

    writer.RenderBeginTag(HtmlTextWriterTag.A);
    writer.AddAttribute("href", null);
    writer.Write("Delete");
    writer.RenderEndTag();
}

When I get to this method in my html helper class that I made it goes through this for loop based on how many columns are in a string[] columns parameter. The first time it goes around I get this

<a>Delete</a>

2nd time it goes around

<a href="">Delete</a>

3rd time I get

<a href="">Delete</a>

and so on.

why is the first one missing the “href”? I don’t understand it.

One more thing the writer is being passed also as a parameter in.

Here is a console app. I just throw quickly together

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var writer = new HtmlTextWriter(new StringWriter());

            string[] columns = new string[4];
            columns[0] = "hi";
            columns[1] = "bye";
            columns[2] = "hi";
            columns[3] = "bye";

            foreach (var columnName in columns)
            {

                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.AddAttribute("href", "g");
                writer.Write("Delete");
                writer.RenderEndTag();
            }
            Console.WriteLine(writer.InnerWriter.ToString());
        }
    }
}
  • 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-12T09:37:35+00:00Added an answer on May 12, 2026 at 9:37 am

    Change the sequence of statements:

    writer.AddAttribute("href", "g");
    writer.RenderBeginTag(HtmlTextWriterTag.A);                                
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this : <table> @foreach(var foo in Model.List) { <tr> <td><a href=# class=MnuCustomerSelect
I have this code @if (ViewBag.TechnologyNames != null) { foreach (var technologyName in ViewBag.TechnologyNames)
I have some code that looks like this: foreach(var obj in collection) { try
I have the following code: foreach (var control in this.Controls) { } I want
I have this href defined in my markup: foreach (Car car in Model.Cars) {
I have this code: foreach (var item in ListView1.Items) { ListView1.Items.Remove(item); ListView21.Items.Add(item); } the
I have this code <% foreach (var item in Model.List) { %> <tr> <td><%:
I have this one in View: <% foreach (var item in (List<MyType>)ViewData[MyTypeArray]) { %><tr>
Currently have this: foreach (var series in Chart1.Series) { series.Enabled = false; } I
I have this asp.net code: @foreach( var database in Model) { if (!(firstTime ==

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.