title: How do I update a model value in JavaScript in a Razor view?
body: <p>I want to update model value in JavaScript as below but it is not working.</p>
  
  <pre><code>function updatePostID(val)
  {
      @Model.addcomment.PostID = val;
  }
  </code></pre>
  
  <p>in Razor view as shown below</p>
  
  <pre><code>foreach(var post in Model.Post)
  {
      &lt;br/&gt;
      &lt;b&gt;Posted by :&lt;/b&gt; @post.Username &lt;br/&gt;
      &lt;span&gt;@post.Content&lt;/span&gt; &lt;br/&gt;
      if(Model.loginuser == Model.username)
      {
          @Html.TextAreaFor(model =&gt; model.addcomment.Content)
          &lt;button type="submit" onclick="updatePostID('@post.PostID');"&gt;Add Comment &lt;/button&gt;
      }
  }
  </code></pre>
  
  <p>Can anyone tell me how to assign model value in JavaScript?</p>