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

  • Home
  • SEARCH
  • 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 8260671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:09:03+00:00 2026-06-08T03:09:03+00:00

I have finally found the time to start learning KnockoutJS while building a new

  • 0

I have finally found the time to start learning KnockoutJS while building a new MVC4 application. I am trying to figure out the best way to initialize an observable value from a default value that is already set in the view.

This is a contrived example, but I would like to render out a default value for an observable directly to the view as follows:

<input type="hidden" 
       value="@Model.SomeValue"
       data-bind="value: myObservableReference"/>

I know that a default value is normally initialized via:

model.myObservableReference = ko.obervable("SomeValue");

However, I would like to find a way to extend the initialization such that:

model.myObservableReference = ko.obervable();

would read the existing value from the binding if a value exists.

As I have so far managed to keep my KnockoutJS code completely unaware of the razor world, I want to to avoid the sloppiness of:

model.myObservableReference = ko.obervable(@Model.SomeValue);

I am guessing this would be handled via either an extender or custom binder, but if someone could point me in the right direction it would be greatly appreciated.

  • 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-08T03:09:04+00:00Added an answer on June 8, 2026 at 3:09 am

    You could try creating your own custom binding handler to achieve this:

    ko.bindingHandlers.initializeValue = {
        init: function(element, valueAccessor) {
            valueAccessor()(element.getAttribute('value'));
        },
        update: function(element, valueAccessor) {
            var value = valueAccessor();
            element.setAttribute('value', ko.utils.unwrapObservable(value))
        }
    };
    
    <input type="hidden" value="@Model.SomeValue"
           data-bind="initializeValue:myObservableReference, value: myObservableReference"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having the worst time trying to figure this out. I'm quite confused
I am finally asking this question as I have never actually found an answer.
I have finally worked out how to get stdin and stdout to pipe between
I have finally gotten my login application to function with my online database. I
EDIT I have finally figured out the problem i have been having on my
Currently I am trying to add a preference activity into my application but found
I have stored procedure that insanely times out every single time it's called from
I finally have finished a Web Application and now I have to make it
I have finally made a production worthy app with play, and use the play
I have finally decided to go with the Entity Framework since it has the

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.