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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:38:23+00:00 2026-05-18T02:38:23+00:00

I cannot make sense of this… The simplified code below OUGHT to insert a

  • 0

I cannot make sense of this…

The simplified code below OUGHT to insert a new form field of the current time’s second value.

Instead, even though the list manipulation happens correctly (as verifiable within the controller and in the debug output), the View does render an additional element, but seems to be just a copy of the final field’s value (prior to submit). This can be verified by changing a field prior to submit – the values stick and the new element is a duplicate of the submitted final value.

The part that really cooks my noodle is that if I trivially change the operation from an Insert() to an Add(), the Add() works as expected!!

Using this example Model:

public class MyViewData
{
  List<string> stringData = new List<string>();
  public List<string> StringData { get { return stringData; } }
}

And this Controller:

public class TestController : Controller
{
  public ActionResult Index()
  {
    return View(new MyViewData());
  }

  [HttpPost]
  public ActionResult Index(MyViewData data)
  {
    data.StringData.Insert(0, DateTime.Now.Second.ToString());

    return View(data);
  }
}

And this View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Forms.Controllers.MyViewData>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Test
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%      
        System.Diagnostics.Debug.WriteLine("---");
        for (var i = 0; i < Model.StringData.Count; i++)
            System.Diagnostics.Debug.WriteLine("{0}", Model.StringData[i]);
    %>

    <% using (Html.BeginForm()) { %>

        <% for (var i = 0; i < Model.StringData.Count; i++) { %>

            <%: Html.TextBoxFor(model => model.StringData[i])%></br>

        <% } %>

        <div><input type="submit" value="Do it" /></div>

    <% } %>
</asp:Content>
  • 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-18T02:38:24+00:00Added an answer on May 18, 2026 at 2:38 am

    This is the normal behavior of standard HTML helpers and is by design. When rendering the input field they will first look at the request POSTed values and only after in the ViewData and view model. This basically means that you cannot change POSted values in your controller action.

    So if you have a form with an input field:

    <%= Html.TextBoxFox(x => x.Id) %>
    

    which is posted to the following action

    [HttpPost]
    public ActionResult Index(MyModel model)
    {
        model.Id = "some new value";
        return View(model);
    }
    

    when rendering the view back the html helper will use the posted value. You could either write a custom html helper that does the job for you or handle it manually (absolutely not recommended but for the record):

    <input type="text" name="StringData[<%= i %>]" value="<%= Model.StringData[i] %>" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This error is weird and i cannot make much sense of it. I've installed
I cannot figure out how to make a C# Windows Form application write to
I am storing objects in a buffer. Now I know that I cannot make
We're testing WYSIWYG editors, and we cannot see to make them work with asynchronous
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I cannot correctly position the div form in my layout. By looking at my
I cannot understand how this is possible. Please help!! I have an app with
I am new to Haskell and facing a "cannot construct infinite type" error that
Please, consider the following (I'm sorry for the amount of code; but this is
I cannot figure out how to change the title bar icon (the icon in

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.