PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 23, 2022

[FIXED] How to read a c# server side value in jquery

 July 23, 2022     asp.net, c#, javascript, jquery, json     No comments   

Issue

I've a JArray response value like below

{[
  {
    "id": "90b254dc-3fcd-4e7c-9943-59bce366ccdc",
    "invoice_number": "510002500007368" 
  }
]}

i'm getting this value from c# class ..when I try to read in jQuery like below ways

  var tmp = '@Model.Transactions';
    var tmp = Model.Transactions;
    var tmp = @Model.Transactions;

from that I'm getting the values like below image ... i need a structured values. let me know if any idea.. thanks

Response Value Image


Solution

You need to render it in a "raw" manner like this, without escaping or encoding so it will remaing "correct" JSON:

var tmp = @:Model.Transactions;

You can also for example prepare your JSON string in the controller e.g. Model.MyJson then use @:Model.MyJson in the view (notice : after @).

This is shortcut for @Html.Raw(myJson);



Answered By - Mzn
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing