title: New line characters in text area increases text length in C#
body: <p>I have this problem in my asp.net mvc application.</p>
  
  <p>In one of my model there is a field "Description". The database column for this fields is set to <code>NVarchar(300)</code>.</p>
  
  <p>In my view I am creating a a text area as following.</p>
  
  <pre><code>@Html.TextAreaFor(m =&gt; m.Description, new { maxlength = "300" })
  </code></pre>
  
  <p>I am using "jquery.validate.unobtrusive.min.js" for client side validation. So when user types in the textarea and content length goes more than 300 characters it displays message "Please enter no more than 300 characaters." </p>
  
  <p>Everything works fine till the following sceanario comes.
  User enters following data in the text area.</p>
  
  <pre><code>f
  f
  f
  f
  f
  f
  f
  f
  sdfa
  </code></pre>
  
  <p>(this content has 8 new lines)</p>
  
  <p>According to "unobtrusive" validation this content has length 300 <b>(counting each new line "\n" as a single character)</b> so the validation passes and page posts back.</p>
  
  <p>In my C# code, due to Encoding, the same content becomes fo length 308 <b>(Counting each new line "\r\n" as 2 characters)</b> which in tern fails the data base operation as it only allows 300 characters.</p>
  
  <p>If someone is saying that I should have <code>StringLength</code> attribute on this particular property, I have the following reason for not having it.</p>
  
  <p>If I put this attribute the client-side validation does not happen for this particular property, it goes to the server and since the model is not valid it comes back to the page with error message.</p>
  
  <p>Please advise me what could be the possible solution for this?</p>