title: how to set model value with view element text in javascript (MVC 4)
body: <p>I would like to have my model to be set by a value of a view element.
  And then call a method in the controller with the model attribute value as parameter in javascript.</p>
  
  <p>whats the best way of doing this?</p>
  
  <p>something like:</p>
  
  <pre><code>@Model.Attribute = $(ElementId).val(); //&lt;- how can I do this?
  
  '@Html.Action("GetPeople", new { id = @Model.Attribute})';
  </code></pre>
  
  <p>I've been investigating and I cannot find a way of doing this.
  I read and tried  binding between view and model. but when i call @Model.Attribute the value is always default.  Even if I change the textbox value and the model attribute does not change.</p>
  
  <pre><code>@Html.TextBoxFor(m =&gt; m.Code, new { id = "txtAttribute"})
  </code></pre>
  
  <p>I did the model attribute binding in the Controller as you can see</p>
  
  <pre><code> public ActionResult Index()
          {
              var model = new MyModel();
              View("Default", model);
          }
  </code></pre>
  
  <p>I've tried multiple things but they all failed</p>
  
  <pre><code>var modelattribute = '@Model.Attribute';
  modelattribute = '@ViewData["ModelAttribute"]';
  modelattribute = '@Html.Raw(Model.Attribute)'
  modelattribute = '@Html.raw(json.encode(Model.Attribute))'
  </code></pre>
  
  <p>is this possible? or do i have to change my algorithm?</p>
  
  <p><strong>UPDATE: my model code</strong></p>
  
  <pre><code>public class MyModel
  {
  
      public string Attribute{ get; set; }
  
  
  }
  </code></pre>
  
  <p>Thanks a lot,
  Nelssen</p>