How to parse JSON string in ASP.NET MVC viewCompile Views in ASP.NET MVCHow do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How to render an ASP.NET MVC view as a string?In MVC, how do I return a string result?SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session.NET - JSON serialization of enum as stringFile Upload ASP.NET MVC 3.0Razor View throwing “The name 'model' does not exist in the current context”

Why is desire the root of suffering?

Is there a way to make it so the cursor is included when I prtscr key?

How can I get exact maximal value of this expression?

Riley Rebuses that Share a Common Theme

Canon 70D often overexposing or underexposing shots

When do characters level up?

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

What is the difference between nullifying your vote and not going to vote at all?

Is it possible to play as a necromancer skeleton?

Binary Search in C++17

Is the first derivative operation on a signal a causal system?

Is CD audio quality good enough for the final delivery of music?

Windows 10 Programs start without visual Interface

Why doesn't the Earth's acceleration towards the Moon accumulate to push the Earth off its orbit?

How long does it take to crack RSA 1024 with a PC?

Why do airplanes use an axial flow jet engine instead of a more compact centrifugal jet engine?

Ticket sales for Queen at the Live Aid

How can people dance around bonfires on Lag Lo'Omer - it's darchei emori?

When and what was the first 3D acceleration device ever released?

If a person had control of every single cell of their body, would they be able to transform into another creature?

What are the benefits of cryosleep?

General purpose replacement for enum with FlagsAttribute

Is there a down side to setting the sampling time of a SAR ADC as long as possible?

What do different value notes on the same line mean?



How to parse JSON string in ASP.NET MVC view


Compile Views in ASP.NET MVCHow do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How to render an ASP.NET MVC view as a string?In MVC, how do I return a string result?SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session.NET - JSON serialization of enum as stringFile Upload ASP.NET MVC 3.0Razor View throwing “The name 'model' does not exist in the current context”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am inserting JSON string into table, than on listing page in View inside foreach loop I want to parse that JSON string using Razor



@foreach (var item in Model) 
var pr = JsonConvert.DeserializeObject<dynamic>(item.profile);
//getting error
//the 'JsonConvert' does not exist in corrent context
//and also the return type Profile was showing error so I changed it to `dynamic`
<tr>
<td>@pr.Name</td>










share|improve this question



















  • 1





    Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

    – Rahul Sharma
    Mar 24 at 7:18











  • because then I have to use 2 loops, one process it in controller than at view to show

    – user10182659
    Mar 24 at 7:20











  • You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

    – Rahul Sharma
    Mar 24 at 7:22












  • Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

    – Rahul Sharma
    Mar 24 at 7:25






  • 1





    Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

    – Rahul Sharma
    Mar 24 at 19:21


















0















I am inserting JSON string into table, than on listing page in View inside foreach loop I want to parse that JSON string using Razor



@foreach (var item in Model) 
var pr = JsonConvert.DeserializeObject<dynamic>(item.profile);
//getting error
//the 'JsonConvert' does not exist in corrent context
//and also the return type Profile was showing error so I changed it to `dynamic`
<tr>
<td>@pr.Name</td>










share|improve this question



















  • 1





    Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

    – Rahul Sharma
    Mar 24 at 7:18











  • because then I have to use 2 loops, one process it in controller than at view to show

    – user10182659
    Mar 24 at 7:20











  • You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

    – Rahul Sharma
    Mar 24 at 7:22












  • Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

    – Rahul Sharma
    Mar 24 at 7:25






  • 1





    Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

    – Rahul Sharma
    Mar 24 at 19:21














0












0








0








I am inserting JSON string into table, than on listing page in View inside foreach loop I want to parse that JSON string using Razor



@foreach (var item in Model) 
var pr = JsonConvert.DeserializeObject<dynamic>(item.profile);
//getting error
//the 'JsonConvert' does not exist in corrent context
//and also the return type Profile was showing error so I changed it to `dynamic`
<tr>
<td>@pr.Name</td>










share|improve this question
















I am inserting JSON string into table, than on listing page in View inside foreach loop I want to parse that JSON string using Razor



@foreach (var item in Model) 
var pr = JsonConvert.DeserializeObject<dynamic>(item.profile);
//getting error
//the 'JsonConvert' does not exist in corrent context
//and also the return type Profile was showing error so I changed it to `dynamic`
<tr>
<td>@pr.Name</td>







c# asp.net-mvc view json-deserialization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 7:26









marc_s

591k13311301278




591k13311301278










asked Mar 24 at 7:13







user10182659














  • 1





    Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

    – Rahul Sharma
    Mar 24 at 7:18











  • because then I have to use 2 loops, one process it in controller than at view to show

    – user10182659
    Mar 24 at 7:20











  • You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

    – Rahul Sharma
    Mar 24 at 7:22












  • Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

    – Rahul Sharma
    Mar 24 at 7:25






  • 1





    Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

    – Rahul Sharma
    Mar 24 at 19:21













  • 1





    Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

    – Rahul Sharma
    Mar 24 at 7:18











  • because then I have to use 2 loops, one process it in controller than at view to show

    – user10182659
    Mar 24 at 7:20











  • You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

    – Rahul Sharma
    Mar 24 at 7:22












  • Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

    – Rahul Sharma
    Mar 24 at 7:25






  • 1





    Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

    – Rahul Sharma
    Mar 24 at 19:21








1




1





Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

– Rahul Sharma
Mar 24 at 7:18





Why don't you deserialize your object of type Profile in your controller and the send it to your razor view as a List?

– Rahul Sharma
Mar 24 at 7:18













because then I have to use 2 loops, one process it in controller than at view to show

– user10182659
Mar 24 at 7:20





because then I have to use 2 loops, one process it in controller than at view to show

– user10182659
Mar 24 at 7:20













You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

– Rahul Sharma
Mar 24 at 7:22






You do not need to loop to deserialize your object in your controller. Just usevar pr=JsonConvert.DeserializeObject<Profile>(item.profile.ToString()); in your controller and then loop over pr which I assume is a List to get your properties on your razor view.

– Rahul Sharma
Mar 24 at 7:22














Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

– Rahul Sharma
Mar 24 at 7:25





Or if you really want to parse your JSON string in your View, try: var pr = JSON.parse(@Html.Raw(Json.Encode(item.profile))); // returns Object

– Rahul Sharma
Mar 24 at 7:25




1




1





Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

– Rahul Sharma
Mar 24 at 19:21






Then add the following line in your view: @using Newtonsoft.Json; .This will get your JsonConvert method to run in your view.

– Rahul Sharma
Mar 24 at 19:21













1 Answer
1






active

oldest

votes


















0














When your application grows large you will feel it's better to use the standard approach of Model-View-Controller. It may become difficult to recode your application at that time. You can use this approach instead:



  1. Create a class for JSON response.

  2. Create a Model class that includes JSON class as a property, and all the other things required by your View.

  3. Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.

  4. Traverse the Model (not JSON) in your View.

If you're just testing something temporarily then you can add @using Newtonsoft.Json on top of your view to make it recognize the JsonConvert.DeserializeObject method.






share|improve this answer























  • Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

    – Rahul Sharma
    Mar 25 at 4:38











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321516%2fhow-to-parse-json-string-in-asp-net-mvc-view%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














When your application grows large you will feel it's better to use the standard approach of Model-View-Controller. It may become difficult to recode your application at that time. You can use this approach instead:



  1. Create a class for JSON response.

  2. Create a Model class that includes JSON class as a property, and all the other things required by your View.

  3. Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.

  4. Traverse the Model (not JSON) in your View.

If you're just testing something temporarily then you can add @using Newtonsoft.Json on top of your view to make it recognize the JsonConvert.DeserializeObject method.






share|improve this answer























  • Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

    – Rahul Sharma
    Mar 25 at 4:38















0














When your application grows large you will feel it's better to use the standard approach of Model-View-Controller. It may become difficult to recode your application at that time. You can use this approach instead:



  1. Create a class for JSON response.

  2. Create a Model class that includes JSON class as a property, and all the other things required by your View.

  3. Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.

  4. Traverse the Model (not JSON) in your View.

If you're just testing something temporarily then you can add @using Newtonsoft.Json on top of your view to make it recognize the JsonConvert.DeserializeObject method.






share|improve this answer























  • Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

    – Rahul Sharma
    Mar 25 at 4:38













0












0








0







When your application grows large you will feel it's better to use the standard approach of Model-View-Controller. It may become difficult to recode your application at that time. You can use this approach instead:



  1. Create a class for JSON response.

  2. Create a Model class that includes JSON class as a property, and all the other things required by your View.

  3. Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.

  4. Traverse the Model (not JSON) in your View.

If you're just testing something temporarily then you can add @using Newtonsoft.Json on top of your view to make it recognize the JsonConvert.DeserializeObject method.






share|improve this answer













When your application grows large you will feel it's better to use the standard approach of Model-View-Controller. It may become difficult to recode your application at that time. You can use this approach instead:



  1. Create a class for JSON response.

  2. Create a Model class that includes JSON class as a property, and all the other things required by your View.

  3. Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.

  4. Traverse the Model (not JSON) in your View.

If you're just testing something temporarily then you can add @using Newtonsoft.Json on top of your view to make it recognize the JsonConvert.DeserializeObject method.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 2:03









joym8joym8

1,81122248




1,81122248












  • Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

    – Rahul Sharma
    Mar 25 at 4:38

















  • Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

    – Rahul Sharma
    Mar 25 at 4:38
















Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

– Rahul Sharma
Mar 25 at 4:38





Yes, this is pretty much what I was trying to explain to the OP. Using the traditional MVC approach is the best and most efficient way.

– Rahul Sharma
Mar 25 at 4:38



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321516%2fhow-to-parse-json-string-in-asp-net-mvc-view%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript