Question: I have the following code which detects which search engine and what search term has been used:

```
if (document.referrer.search(/google\.*/i) != -1) {
    var start = document.referrer.search(/q=/);
    var searchTerms = document.referrer.substring(start + 2);
    var end = searchTerms.search(/&/);
    end = (end == -1) ? searchTerms.length : end;
    searchTerms = searchTerms.substring(0, end);
    if (searchTerms.length != 0) {
        searchTerms = searchTerms.replace(/\+/g, " ");
        searchTerms = unescape(searchTerms);
        alert('You have searched: '+searchTerms+' on google');
    }
}

```

That actually works, but unfortunately it doesn't work as expected sometimes.

Sometimes if the referrer was even not google i get an alert with the search term as : ttp://www.domain.com ( without H at the start ) i think that may lead to the bug.

Appreciate any help!

Answer: 
You could define an interface for those classes.

```
interface IRecord
{
    string RecordID { get; set; }
    string OtherProperties { get; set; }
}

```

and make the method receive the model by using that:

```
[HttpPost]
public ActionResult ValidateRecordID(IRecord model) 
{
    // TODO: Do some verification code here

    return this.Json("Validated.");
}

```
If you only need the RecordID, you can just have the controller method take int RecordID and it will pull that out of the form post data instead of building the view model back up and providing that to your action method.

```
[HttpPost]
public ActionResult ValidateRecordID(int RecordID) {
    // TODO: Do some verification code here

    return this.Json("Validated.");
}

```