0

I have a product listing page. All the products are display based on 3 criteria :

  1. When user click on the left menu
  2. When user input in search text box and search
  3. When user choose in the brand combo box

This is the exam url due to the user click the below list :

  1. http://mysite.com/Products?dep=1&cat=2&tab=2 : display the product that have depId = 1 , and categoryID = 2.
  2. http://mysite.com/Products?brand=ABC_2&tab=2 : display the product that have the brand name = "ABC" and brand id=2
  3. http://mysite.com/Products?tab=2&search=ABCD : display the product that the product name = "ABCD"

Problem : When the user click on each link below, the page will refresh, so I cannot mix the parameter string together. I want to combine these 3 criteria together, mean when the user click on (1) then continue to (2) and (3), the url will :

http://mysite.com/Products?dep=1&cat=2&brand=ABC_2&search=ABCD&tab=2

So the page will display the product that have depID = 1, categoryID = 2, brand id = 2, brand name = ABC and product name = "ABCD".

This is what I have tried to get the (3) in my site.master :

function SearchClick() {
   window.location = "/Products?tab=2" + ($("#txtsearch").val() != "" || $("#txtsearch").val() 
   == "undefined" ? "&search=" + $("#txtsearch").val() : "");
}

Thanks in advanced.

3 Answers 3

1

I notice you are using jQuery, I will suggest:

//using Request.Params
string Dept = Request.Params["dep"];
string Cat = Request.Params["cat"];
string Brand = Request.Params["brand"];
//capture the char after '?' or '&' and pass into Params["char"]
//do your search function.

This link will help you.

If you want to keep it after page refresh you can store it in Session.

string theDept = Request.Params["dep"];
Session["dep"] = aa;    

string dep = (string)Session["dep"];
Sign up to request clarification or add additional context in comments.

5 Comments

Error : Object reference not set to an instance of an object, with declaration Session["dep"] = Request.Params["dep"].ToString();
Session["dep"] = theDept; or Session["dep"] = aa;
But while I tried to use the session, after my page refreshed, it lose the session value.
Where did you put the session?
1

This should get you started

Back end:

  • create a SearchModel with 3 properties: search, brand, dep
  • have an action Product that takes in the search model

Front end:

  • create a form that posts to the Product action above, make sure it has a submit button
  • create a textbox inside that form with id/name = 'search'
  • create a ddl inside that form with id/name = 'dep'
  • create a hidden field inside that form with id/name = 'brand'

  • use jquery, to update the hidden field when the user clicks on the left column

  • use jquery to submit the form anytime the user: hits the submit button, changes the ddl, or clicks on the left column

Comments

1

You can also try this if you are using ajax to load your pages.

    $.ajax({
        url: '/Products',
        type: 'GET',
        dataType: 'json',
        cache: false,
        async: false,
        data: { dep: 1, brand: abc_2, search:abcd, tab:2 },
        success: function (data) {
        //Do your work here
              },
        error: function (ex) {
            alert('Error.');
        }

    });

You'll typically put the 3 criteria in the same page like search textbox, brand/department dropdown and then on a button click will fire this query.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.