Using Linq to Transform Rows into Columns

I have a table that looks like this:

ID   Attributes           Value

1   Name                  Jason  
2   Age                   14
3   Address               12 Test Road

A linq query has been created to select each value based on its ID

from p in db.people
where p.attributes.contains(string) || p.value.contains(string)                  
select p.attributes , p.value , 

Now, the challenge arises when displaying this data in JSON format in an MVC View. Each value is outputted in separate rows within individual div elements (which are incremented) using the following JavaScript code:

 item.attributes + item.value

Current Output

Div 1
-------
Name - Jason

Div 2
--------
Age - 14

Div 3
--------- 
Address - 12 Test Road 

Is there a way to have all these rows within a single div instead of separate div elements? Alternatively, is it possible to view the data as columns instead of rows?

Answer №1

1) It's important to understand the JSON data being returned, which consists of an array of objects.

2) Consider how you want the JSON data to be displayed in the user interface. One approach is to use a single div for each array element. To achieve this, loop through the JSON data and bind/emphasize the values in the UI element inside the div according to your preferred method. For further guidance, refer to the answer provided in response to the question on how to loop through JSON result with jQuery

I hope this explanation is helpful. Happy coding!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show specific button text when no file has been selected

I have a form with an image container that allows users to change the photo. The icon opens a file browser, and when the user selects a file, the Change button submits the photo and updates it. https://i.sstatic.net/R5vwn.jpg If no file is selected, I wa ...

Obtaining a complete element from an array that includes a distinct value

I'm attempting to retrieve a specific item from an array that matches a given value. Imagine we have an array const items = ["boat.gif", "goat.png", "moat.jpg"]; We also have a variable const imageName = "boat" Since we don't know the file ex ...

How to serialize a Golang struct as null when it contains no fields?

While this might seem like a common query, I appreciate your patience... Say I have a struct with one of its fields being the same type as another struct: type Developer struct { Name string `json:"name,omitempty"` ProjectRef *Ref ...

Is it possible to run my NPM CLI package on CMD without needing to install it globally beforehand?

I've created a new NPM package, complete with its own set of CLI commands. Let's call this package xyz, and let's imagine it's now live on npmjs.com Now, picture a user who installs this package in their project by executing npm insta ...

Using ReactJS to pass an onClick event to a different component

Is there a way to implement the onClick event on an anchor tag to update state in another component? Utilizing onClick in Card.js Component import React from 'react' import PropertyLightbox from '../global/PropertyLightbox' const Car ...

Implementing the array name property in a JSON object using ES5

I am currently working with a JSON object that has the following structure: {"Firstname":"john","Lastname":"doe"} My goal is to transform it into an array with a specific name 'abc': users: [{"Firstna ...

Increment by 1 until a specific number is reached instead of displaying all numbers within an array

I have an array of numbers and for each number in the array, a request is sent to an external website using the number as a URL variable. The webpage content is then displayed. Instead of manually listing the numbers (1, 2, 3, 4, 5, 6, 7, 8, 9) in the arr ...

Introducing Vee Validate 3.x and the ValidationFlags data type definition

I'm currently struggling to locate and utilize the ValidationFlags type within Vee-Validate 3. Despite my efforts, I am encountering difficulties in importing it. I am aware that this type is present in the source code located here. However, when I a ...

Explore the List feature in Tapestry using jQuery

On the Index.java page, I have a List of user favorites that I retrieve using userService: List<Favorite> favorites = userService .getFavoritesByUserId(userSession.getUsrId()); JSONArray jsonArray = new JSONArray(); for (Favori ...

What could be the reason for this code returning a "module not found" error?

Within localbase.js... const fs = require("fs"); if(!fs.existsSync(__dirname + "/localbase.json")) fs.writeFileSync("./localbase.json", "{}"); let database = require("./localbase.json"); The code abov ...

The controller is unable to provide the output in JSON format within the AJAX response

My task requires me to continuously call and fetch data from a REST API every second. To achieve this, I am calling the method with a time interval of 1 second as shown below: var myVar = setInterval(function(){ getData1() }, 1000); Below is the JavaScri ...

Tips for accessing information from an Angular Resource promise

I am currently facing an issue when trying to read data from an angular promise that was returned. Before, I had the following code: var data = category.get({id:userid}); Later, I realized that the data being returned was an unresolved promise. So, I ma ...

Uploading files with Ajax in PHP

Illustration of my Ajax script: Script <script type="text/javascript> $(document).ready(function(){ $('.costExcel').on("submit",function(event){ event.preventDefault() var url = "ajax.php"; ...

Transfer files with Ajax without the need for a form tag or submission

I'm trying to send images via AJAX without submitting a form. Normally, when submitting a form I can access the images using $_FILES['images']['tmp_name']; However, when trying to send files, I receive an object FileList in an arra ...

Customizing the Slider Range with HTML DOM Style's BackgroundImage Attribute

I have a slider range that I'd like to modify using JavaScript. Specifically, I want to change its background-image property. To achieve this, I attempted the following script: document.getElementById("range").style.backgroundImage = "linear-gradient ...

Guide to generating dynamic arrays in JavaScript when a button is clicked

I am working on a JavaScript program where I dynamically generate buttons and div tags, as well as retrieve data from a local JSON file. My goal is to implement a new feature where clicking a button will create an array with the same name as the button, al ...

Retrieve the current state of the toggle component by extracting its value from the HTML

I have a unique component that consists of a special switch and several other elements: <mat-slide-toggle (change)="toggle($event)" [checked]="false" attX="test"> ... </mat-slide-toggle> <p> ... </p> F ...

Ways to rotate just the border without rotating the icon through CSS

I need help with rotating only the border 135 deg on hover, without affecting the icon. Below is the code I am using. Any assistance would be greatly appreciated. Thank you! My html: ` <div class="container-fluid details-section"> ...

Save information to a server-side .xml file with the use of either JavaScript or PHP

I have a website built using HTML and JavaScript. Currently, I am successfully retrieving data from a server-side .xml file on the site. Everything is working perfectly! However, I am facing issues with allowing users to input data into a field and save ...

Tips for successfully retrieving a span value in VUE

I am working with forms <input type="text" v-model="email"> <span>Extracted Value</span> Can someone help me figure out how to pass the value from the span element? data () { return { email: '/*Here goes the extracted valu ...