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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:19:45+00:00 2026-06-18T04:19:45+00:00

i try to learn knockout.js on asp.net mvc razor. i have been coding below

  • 0

i try to learn knockout.js on asp.net mvc razor. i have been coding below code to learn and test myself
But View side throws me a js error.

Error occurs on “var model = @Html.Raw(Json.Encode(Model));” Error : Microsoft JScript run-time error: ‘fromJSON’ Unable to get value of the property: the object is empty or undefined

Controllers:


  [HttpGet]
        public ActionResult GetGift()
        {
            GiftModel gift = new GiftModel();
            gift.Price = 120;
            gift.Title = "Test";

            return View(gift);
        }

View:    

@using System.Web.Script.Serialization;
@model knockout1.Models.GiftModel

@{
    ViewBag.Title = "GetGift";
}

<h2>GetGift</h2>

<script src="/Scripts/knockout-2.1.0.js" type="text/javascript"></script>


<script type="text/javascript">

var initialData =   @Html.Raw( new JavaScriptSerializer().Serialize(Model));

var viewModel = ko.mapping.fromJSON(initialData);

    $(document).ready(function () { ko.applyBindings(viewModel); });
    </script>



<p>Title: <strong data-bind="text: Title"></strong></p>
<p>Price: <strong data-bind="text: Price"></strong></p>

But i changed my js codes. Error disappears. i can not understand first usage why doesn’t correct? i readed Darin Dimitrov’s response:

Darin Dimitrov :


<script type="text/javascript">
    var jsonResultData = @Html.Raw(Json.Encode(Model));
</script>

Me: (it is working good.)


<script type="text/javascript">

   $(function()
   {
      var model = @Html.Raw(Json.Encode(Model));


// Activates knockout.js
ko.applyBindings(model);
   });

</script>
  • 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-18T04:19:46+00:00Added an answer on June 18, 2026 at 4:19 am

    Based on the error message

    ‘fromJSON’ Unable to get value of the property: the object is empty or undefined

    and page setup your problem is that you are trying to use the KO mapping plugin without including the plugin.

    All the methods which are string with ko.mapping are part of the mapping plugin and for using them you need to refeence the knockout.mapping.js file in your HTML page.

    Can you can download mapping plugin from github

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi; i try to learn knockout.js using asp.net mvc razor. i have been written
i try to learn asp.net Profile management. But i added below xml firstName,LastName and
I am following along with the music store example to try learn ASP.NET MVC.
Hi! i try to learn Asp.net MVC.i created a sample application to learn it.
I am doing the below test to try and learn more about LINQ to
I'm new to the programming world and have been experimenting to try and learn
I am just beginning to try to learn C and have been trying to
I am working with this example to try and learn Sencha Touch. I have
Hello I'm very new to OpenGlES and i have started to try to learn
I try to learn Grand Central Dispatch (GCD) and use the following code to

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.