1

I am trying to store a Knockout variable's value in Razor server side code. Something like this

@{
  String test = KNOCK_OUT_VARIABLE;
}

in a .cshtml file.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
mohsinali1317
  • 4,255
  • 9
  • 46
  • 85
  • 1
    you can't . `ko` is client side where razor is server side . ko variables i interpret those are observables which are local to vm you cannot use them in your razor but you can do opposite . – super cool Jun 30 '15 at 09:46

1 Answers1

2

This is not possible / you're looking at this the wrong way.

You're confused about the differences / border / gap / relation between server side and client side programming (see also this PHP version of a related question). To get Knockout values (client side) to your Razor and/or Controllers you need to GET or POST something, including the client side value in your request.

You should probably read up on how client and server interaction work in general, and/or follow some tutorials. The Knockout tutorials are pretty good and have a relevant tutorial about loading/saving data.

Community
  • 1
  • 1
Jeroen
  • 60,696
  • 40
  • 206
  • 339