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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:57:29+00:00 2026-06-06T20:57:29+00:00

I am using Json.net to convert a json string into a dynamic. When I

  • 0

I am using Json.net to convert a json string into a dynamic. When I use this dynamic as a model for a Razor template, I am getting an error…

Unable to compile template. ‘Newtonsoft.Json.Linq.JObject’ does not
contain a definition for ‘Name’ and no extension method ‘Name’
accepting a first argument of type ‘Newtonsoft.Json.Linq.JObject’
could be found (are you missing a using directive or an assembly
reference?)

If I just use a simple anonymous object as the model, it works fine.

Here is the problem displayed in a simple console app where I used NuGet to pull in two libraries…Newtonsoft JSON and RazorEngine.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // template used for generation
            var template = "<div>Hello @Model.Name</div>";

            // create model
            dynamic model = new System.Dynamic.ExpandoObject();
            model.Name = "Foo";

            // this works just fine
            RazorEngine.Razor.Parse(template, model);

            // convert model to string
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(model);

            // regenerate model
            model = Newtonsoft.Json.Linq.JObject.Parse(json);

            // this prints 'Foo' to the console just fine so the model is valid!
            string name = model.Name;
            System.Diagnostics.Debug.WriteLine(name);

            // this throws the error above!
            RazorEngine.Razor.Parse(template, model);
        }
    }
}

Can someone help me with the problem here?

  • 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-06T20:57:31+00:00Added an answer on June 6, 2026 at 8:57 pm

    You can’t directly pass the JObjects into the RazorEngine because whenever you assign a value to the JObject they are stored as type JValue. When you try to retrieve the assigned value also you will get a JValue not the assigned one.

    Ex.

    dynamic person = new JObject();
    person.Name = "Vijay";
    
    Console.WriteLine(person.Name.GetType());
    
    ==> NewtonSoft.Json.Linq.JValue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to convert JSON string to .net object in asp.net. I am
I'm using JSON.Net for serializeation. I need my data to look like this json
How to convert datatable to json using json.net? Any suggestion... I ve downloaded the
I'm using Asp.Net-Mvc, I have this method in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult LinkAccount(string
I am using Json.Net library to convert objects to json and back to objects.
I am using Json.Net library to convert objects to json and back to objects.
I'm trying to convert JSON to C# object using Json.NET. The object looks like
im trying to convert my result from a linq query to json using json.net
I am using json.net to convert currency rates to json. The C# entity got
I'm using gson to convert a json string to a Java-Object. The value of

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.