title: How to Store and Edit Data from Index.cshtml
body: <p>I have a model with 4 fields: </p>
  
  <pre><code>    public string facility { get; set; }
      public string hub{ get; set; }
      public double customerCount { get; set; }
      public double cmtsValue { get; set; }
  </code></pre>
  
  <p>the cmtsValue is the customercount divided by the sum of each customerCount which is shown here: </p>
  
  <pre><code>        @{     
                  double totalValues = Model.Sum(c =&gt; c.customerCount);
                  double cmtsValue = (item.customerCount / (totalValues * 1.0));
                  @Html.Raw(cmtsValue.ToString("0.##%"))
          }
  </code></pre>
  
  <p>This formula is done in the Index.cshtml using Razor Code. In the View it shows up correctly but in the database its still stored as 0,
  how can I save changes or edit values straight from the index.cshtml? I tried using the approach from Create.cshtml and Edit.cshtml but I am having no luck</p>
  
  <p>EDIT: What I have tried doing is adding a method in my ViewController: </p>
  
  <pre><code>    public void SaveCMTSValue(int? id, double totalValues, double cmtsValue)
      {
          FacilityEditor facilityEditor = db.FacilityEditor.Find(id);
          if(ModelState.IsValid)
          {
              facilityEditor.cmtsValue = cmtsValue;
              db.SaveChanges();
          }
  
      }
  </code></pre>
  
  <p>then in my Index.cshtml is the following code: </p>
  
  <pre><code>        @{
  
  
              double totalValues = Model.Sum(c =&gt; c.customerCount);
              double cmtsValue = (item.customerCount / (totalValues * 1.0));
                  @Html.Raw(cmtsValue.ToString("0.##%"))
  
  
              @Html.ActionLink("SaveCMTSValue", "SaveCMTSValue", "FacilityEditor", new { id = item.ID, totalValues = totalValues, cmtsValue = cmtsValue })
  
          }
  </code></pre>
  
  <p>But I'm just getting an error, whats a substitute for an actionlink if I want the data to be added automatically. </p>
  
  <p>Error: 
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p>