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;
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
|
show 3 more comments
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
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
|
show 3 more comments
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
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
c# asp.net-mvc view json-deserialization
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
|
show 3 more comments
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 use
var 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 use
var 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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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:
- Create a class for JSON response.
- Create a Model class that includes JSON class as a property, and all the other things required by your View.
- Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.
- 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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
- Create a class for JSON response.
- Create a Model class that includes JSON class as a property, and all the other things required by your View.
- Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.
- 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.
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
add a comment |
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:
- Create a class for JSON response.
- Create a Model class that includes JSON class as a property, and all the other things required by your View.
- Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.
- 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.
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
add a comment |
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:
- Create a class for JSON response.
- Create a Model class that includes JSON class as a property, and all the other things required by your View.
- Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.
- 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.
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:
- Create a class for JSON response.
- Create a Model class that includes JSON class as a property, and all the other things required by your View.
- Fetch the JSON from Controller, feed it to the Model, and return the Model to the View.
- 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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 use
var 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