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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:14:48+00:00 2026-05-25T00:14:48+00:00

I have an ASP.NET MVC 3 view using Razor and Knockout.js that is not

  • 0

I have an ASP.NET MVC 3 view using Razor and Knockout.js that is not behaving the way I expect it to. I have a pair of <a> tags that are basically ‘agree’/’disagree’ links and a text area for comments. If the user clicks ‘disagree’ we add a CSS class to the textarea to highlight the fact that comments are required when the user disagrees. The problem occurs if the comments field coming from the server is null or or "", which it always is the first time the user visits the page. If the user enters comments and then clicks either of the ‘agree’ or ‘disagree’ links, the comments disappear. If the comments field has a value when the page first loads, the comments are persisted when the user clicks the links. If I remove the data-binding that updates the CSS, everything works fine.

Here’s a slightly simplified version of the code involved (I’ve removed the parts of the viewModel that aren’t related to this section of the page):

<a href="#" onclick="viewModel.meetsCriteria('true'); return false;">
    Agree
</a>
<a href="#" onclick="viewModel.meetsCriteria('false'); return false;">
    Disagree
</a>

<textarea rows="6" 
    data-bind="value: comments(), css: { 'req': meetsCriteria() == 'false' }" 
    name="response.Comments">
</textarea>

...

var viewModel = {
meetsCriteria: ko.observable(''),
comments: ko.observable('')
};

viewModel.meetsCriteria('@Model.MeetsCriteria.ToString().ToLower()');
viewModel.comments('@Model.Comments');

Any ideas about what’s happening or how to fix it are 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-05-25T00:14:49+00:00Added an answer on May 25, 2026 at 12:14 am

    You will want to remove the () from value: comments().

    For a read/write binding like value it is important that you are binding against the actual observable and not the value of it. In your case, the binding receives the value of the comments observable and won’t be able to read/write to the actual observable.

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

Sidebar

Related Questions

I am using ASP.NET MVC 3 with the razor view engine. I have the
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured
How can i directly access a .cshtml file in ASP.NET MVC using razor view
I am using Razor view engine in ASP.Net MVC 3 RC 2. This is
I'm using ASP.NET MVC 3 (Razor) and have created a Controller named Controllers -
using ASP.NET MVC, I have a Model, to which I'm attaching attributes so that
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have an ASP.Net MVC Ajax.BeginForm that submits and updates my page properly when

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.