user1770470
user1770470

Reputation: 31

Webmatrix Search

I have my first site running in webmatrix c# with various basic searches however i need to do an advaced search with multiple options.

Its a property site so i need to have a search option for

1: property type(checkbox)

2: Region(dropdown),

3; Area(checkbox) 

4: min size - max size(text input).

Please can someone point me in the right direction

Upvotes: 2

Views: 107

Answers (1)

Ifeanyi Chukwu
Ifeanyi Chukwu

Reputation: 3337

Your attempt was valid, I'll help you complete it.

if(IsPost){
var Pinsimg = "gmarker.png";    
var temp = Request["areaId"].Split(new[]{','}, StringSplitOptions.RemoveEmptyEntries).ToList();

    var parms = temp.Select((s, i) => "@" + i.ToString()).ToArray();

    var inclause = string.Join(",", parms); 

    var extraplaceholder = "@" + temp.Count();

    temp.Add(Pinsimg.ToString());

       categories = db.Query(String.Format("SELECT address, id, areaid, pinsimg FROM tblproperty WHERE areaId IN ({0}) and pinsimg = {1}", inclause, extraplaceholder), temp.ToArray());
}

This worked for me. I extracted it from my recent project source code. The code simply bundles your parameters as an array. To add an extra placeholder, first create temp as a LIST, then use the Add method to build a list. Finally parse it as an array to the database. Hope this helps!!!

Upvotes: 1

Related Questions