title: unique random string in MVC3 Razor
body: <p>I want to generate a random 3 digit string in MVC3-Razor-C#.net. But condition is that, before generating random string, i need to check in database i.e. SQL 2008 whether this record is already present or not. If the random generated string is already present in database I need to generate new string. This functionality is for a button called "NextAvailable". I was able to generate random string using JavaScript, but not able to check in database if it is already exists. It would be great if any help me out for this.</p>
  
  <pre><code>Here is my Javascript function which is working fine, but how to check database using AJAX for existence of a string.
  
   function btnNextAvailable_OnClick() {
    $("#nextAvailableButtonClick.val('true')");
    var chars = "0123456789";
    var stringLength = 3;
    var randomstring = '';
    for (var i = 0; i &lt; stringLength; i++) {
    var rnum = Math.floor(Math.random() * chars.length);
    randomstring += chars.substring(rnum, rnum + 1);
    }
    document.getElementById("SequentialId").value = randomstring
    }
  </code></pre>