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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:11:36+00:00 2026-05-26T05:11:36+00:00

I have a table where each tr is grouped by having their input elements

  • 0

I have a table where each tr is grouped by having their input elements name set to a value that is unique for each row.

For example,

    <td>
        <input data-field="opps" type="text" value="somevalue" name="@item.Code" />
    </td>
    <td>
        <input data-field="asc" type="text" value="somevalue2" name="@item.Code" />
    </td>

On POST

[HttpPost]
        public ActionResult Update(FormCollection collection)
        {
            try
            {
                //doin work on collection...order assumed static

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

my System.Web.MVC.FormCollection is grouped in the same order I define the <td>. I don’t like to assume order, but without access to my data-field, I’m not sure what else I can do (maybe I could append the data-field value as a prefix to the name and put it all together with a custom collection and Regex..but that seems nutty).

Is there a way to access the data-field? This way I’m not fragile to re-ordering or adding new columns in the View.

  • 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-26T05:11:37+00:00Added an answer on May 26, 2026 at 5:11 am

    Let’s say you have a class (model) defined like this:

    public class MyModel
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
    }
    

    In you controller, you might have an action called Create, like so:

    [HttpGet]
    public ViewResult Create()
    {
        MyModel sampleModel = new MyModel();
        return View(sampleModel);
    }
    
    [HttpPost]
    public ActionResult Create(MyModel sampleModel)
    {
        if (ModelState.IsValid)
        {
            TempData["Error"] = "There were errors. Please correct the problem and submit again";
            return View(sampleModel);
        }
    
        // At this point everything is fine and you can access data in your sampleModel
        if (sampleModel.Age >= 16)
        {
            return RedirectToAction("LegalAccess");
        }
        else
        {
            TempData["Error"] = "You must be 16 or over to access this site";      
            return RedirectToAction("AgeRestriction");
        }
    }
    

    When you create a strongly typed view that uses MyModel as model you might define it something like this:

    @model MyModel
    
    @{
        Layout = "~/Shared/_Layout.cshtml";
    }
    
    @using (Html.BeginForm()) 
    {
        @Html.LabelFor(m => m.FirstName)
        @Html.TextBoxFor(m => m.FirstName)
        <br />
        @Html.LabelFor(m => m.LastName)
        @Html.TextBoxFor(m => m.LastName)
        <br />
        @Html.LabelFor(m => m.LastName)
        @Html.TextBoxFor(m => m.LastName)
    
        <input type="submit" value="Submit" />        
    }
    

    When you submit this form, the model binder will in the background copy data from this form using Request.Form into an object of type MyModel which it creates in the background. This new object is passed to an action that handles HTTP POST method. With this you get strongly typed object and you don’t have to worry about the order of items in FormCollection.

    I hope I helped answer your question.

    BTW. I wrote this without Visual Studio, so I hope there are not errors. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grouped table view that contains 3 sections and each row per
I have a table where each row has 13 TD elements. I want to
I have a table full of items that each have a unique ItemID .
I have a grouped table with 3 sections, each section with a title. The
I have a table column where each row has one of three states, and
I have a data table filled with text in each table row. How do
I have a SQL table where in each row I store the country and
I have a table with multiple rows in each row is a select list
I have a database table that stores document information (DocID, Name, Type, Owner, etc).
I have a table which contains due dates for individual member records. Each row

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.