title: Variable not being set when using a C# property in an MVC view
body: <p>i'm sorry if its a newbie question but can anyone tell me why can't I set a value of a var to a c# property ?
  i am trying to find a way to use the value to retrieve some model properties &amp; do a calculation .... </p>
  
  <pre><code>@using System.Collections
  @using System.Runtime.Serialization
  @using CarRentalMVCApp.Models
  @model CarRentalMVCApp.Models.Rentals
  
  
  @functions {
      public string selection { get; set; }
      public decimal Price { get; set; }
  }
  @{
  ViewBag.Title = "Create";
  }
  
  
  
  &lt;script&gt;
  
  function select() {
      var $el = $("#selectedCar");
      var selected = $("#selectedCar option:selected").text();
      $el.on("change", @selection = selected);
      alert(@selection); 
  
  }
  
  function Rental() {
  
      var choice = select();
      @foreach (var car in ViewData["availableCars"] as IEnumerable&lt;Vehicles&gt;)
      {
          if (selection != null &amp;&amp; int.Parse(selection) == car.מספר_רכב)
          {
              Price = car.עלות_ליום_השכרה;
          }
      }
      if (firstDay != null &amp;&amp; lastDay != null) {
          var rentalData = {
              price: @Price,
              firstDay: $("#beginRental").val(),
              lastDay: $("#endRental").val()
          }
          alert(rentalData);
      }
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>the @selection always equals 0 and ones I try to set it with another veriable like so:</p>
  
  <pre><code>@selection = selected;
  </code></pre>
  
  <p>it remains 0 !!!</p>
  
  <p>I also cant understand why I can't use any type of javascript variable if the @ sign is involved , would appresiate an explanation if you have the time or the links to help .....</p>