How to get bool value from model

I need to create a Javascript validation that will compare values from text-boxes against values in the model.

($("#Description").val() != "<%= Model.Description %>")

Description is a string in the model, and code above works fine for it.

($("#Weight").val() != <%= Model.Weight %>)

Weight is a int , and works fine.

And finally if I try to check the bool value it doesn't work at all. Any ideas?

($("#PackingFlag").is(':checked') != "<%= Model.PackingFlag %>")



returns a bool.

"<%= Model.PackingFlag %>"

is a string (hence the ")

bool != string always returns true.

if Model.PackingFlag returns the string true or false then removing the " should result in the correct comparision:

($("#PackingFlag").is(':checked') != <%= Model.PackingFlag %>)

client side this results in:

 ($("#PackingFlag").is(':checked') != true)


 ($("#PackingFlag").is(':checked') != false)

Since right hand side of the comparison is a string, you could try converting the left hand side to a string.

(String($("#PackingFlag").is(':checked')) != "<%= Model.PackingFlag %>")

Need Your Help

Service Stack + SignalR - Self Hosted

c# servicestack signalr self-hosting servicestack-razor

I'm building an app that uses ServiceStack for restful api. I'm attempting to integrate SignalR for real time features, as this app will run on the client desktop. Long polling or any such work aro...

google app engine channel api limitations

google-app-engine channel-api

I have been using Google app engine for ~2 years now and love it. I am tasked with making a game and I wanted to use GAE as the backend. From what I understand the Channels API is meant for this ki...