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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:08:23+00:00 2026-06-09T21:08:23+00:00

In my Razor markup, I am looping through my model collection and outputting table

  • 0

In my Razor markup, I am looping through my model collection and outputting table rows. Currently, I am storing the the item ID’s in each table row’s “data-id” attribute. I am needing to store the entire object per row though so it will save me some future ajax calls. What is a good way to store the full object per row on the Razor output for my jQuery to use later?

  • 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-09T21:08:25+00:00Added an answer on June 9, 2026 at 9:08 pm

    Have you considered using something like Knockout.js or any other model-based template Javascript language (there’s plenty, including Backbone, Angular, etc)? You could simply bind your whole model to Javascript (serialize it to JSON). You could then use a template to generate the table. This is the best advice I can give you.

    If you want a quick/hack-ey way, you could always do something like:

    <script>
    var dataMap = {};
    </script>
    
    @foreach(var item in Model.Whatever) {
     <tr data-id="@item.Id"> ... etc </tr>
     <script>
    dataMap['@item.Id'] = @Json(item); // you'd have to make a Html helper to do this
    </script>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why in the following Razor markup @foreach (var item in Model) { <tr> <td>@Html.DisplayFor(modelItem
Here is my razor code: <fieldset> <legend>Headline News</legend> @foreach (var item in Model) {
I have the following razor markup: @{ var initValue = @Html.Raw(new JavaScriptSerializer().Serialize(Model)); @Html.Hidden(initial-namings-data, initValue.ToString());
I have the following markup as a part of a Razor view: <table> <caption>Presidents</caption>
I want to check the URL parameter in my Razor markup. For example, how
Is the following markup incorrect, or is it a bug in the Razor engine
I have this Razor Template <table> <tr> <td>@Html.RadioButtonFor(i => i.Value, 1)</td> <td>@Html.LabelFor(i => i.Value,
Currently I have the following element <h6 class=header> Chance of Precipitation: <span data-bind=text: PrecipitationLabel></span>
I have the following markup in an MVC 3 Razor view. As is, the
This one is strange...I have the following markup for a view using Razor view

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.