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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:30:23+00:00 2026-05-21T16:30:23+00:00

I have a form in my asp.net mvc(C#) application which handles some dynamic controls.

  • 0

I have a form in my asp.net mvc(C#) application which handles some dynamic controls.

On a button click “Add Row”, i will add a row dynamically to the existing table as:

$('#btnAddMore').click(function() {
    var _userBodyHtml = '';
    _userBodyHtml += '<tr><td><input type="text" name="UserName" id="UserName' + _userDynId + '" size="10" /></td>';
    _userBodyHtml += '<td><textarea name="UserComments" id="UserComments' + _userDynId + '" cols="60" rows="1"></textarea></td>';
    _userBodyHtml += '</tr>';
    _userDynId += 1;
    $('#UserBody').append(_userBodyHtml);
});

Then the admin adds the username and comments and submits it.

On submit, i am handling it in controller’s action as:

var _frmUserNames = new List<String>(form["UserName"].ToString().Split(','));
var _frmUserComments = new List<String>(form["UserComments"].ToString().Split(','));
if (_frmUserNames.Count > 0 && _frmUserComments.Count > 0)
{
    List<UserComments> _userComments = Enumerable.Range(0, _frmUserNames.Count)
        .Select(i => new UserComments
        {
            UserName = _frmUserNames[i],
            UserComment = _frmUserComments[i]
        }).ToList();
}

From the above code, the _frmUserComments returns the comma separated value when there are more than one textbox with the same name as i am differentiating the textboxes only with different ids.

The problem is when the admin enters the usercomments which has a comma(,) within that comment, then the form value _frmUserComments has the comma separated value and it gives invalid data to the List.

When Admin enters(Case 1) which is fine:

Sam          Logged on 12/10/2010
David        Looking for enhancement

the form values returns:

_frmUserNames  = "Sam,David"
_frmUserComments = "Logged on 12/10/2010,Looking for enhancement"

When Admin enters(Case 2) which is problem causing:

Sam          Logged on 12/10/2010
David        Logged on 03/01/2011, Looking for enhancement

the form values returns:

_frmUserNames  = "Sam,David"
_frmUserComments = "Logged on 12/10/2010,Logged on 03/01/2011, Looking for enhancement"

How can i handle the scenario like this.

  • 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-21T16:30:24+00:00Added an answer on May 21, 2026 at 4:30 pm

    Try to set dynamic controls name attributes same as IDs (with index – yours’s _userDynId). You’ll be able to iterate through form collection in controller, something like that (using LINQ):

            foreach (var key in form.AllKeys.Where(k => k.StartsWith("UserName")))
            {
                var index = key.Replace("UserName", "");
                var userName = form[key];
                var userComment = form["UserComments" + index];
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form within my Asp.Net MVC application which returns a Null reference
I have a wizard in my asp.net MVC application which is built upon this
I have an ASP.NET MVC project with a form. In the Action method that
I have a simple form with some plain html input like bellow using ASP.NET
I have an ASP.NET web form which I am adding a variable number User
I am working on an ASP.NET MVC application which has a model for a
In an ASP.NET MVC application I have a CartController with this AddToCart action: public
i have a form in Asp.net MVC. On submitting i want to generate the
We have a largely asp.net web form team (With some Oracle developers thrown in).
I have an existing ASP.NET MVC 2 application that I've been asked to extend.

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.