How to pass parameter from javascript for RouteUrl?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi,

In NopCommerce, I want to pass parameter to RouteUrl via Javascript to get Products list.
e.g.
function searchProducts(){    
               //Get selected option from dropdown say parentId
    var selectedLocation = document.getElementById('Location');      
    var parentId = selectedLocation.options[selectedLocation.selectedIndex].value;    
    
               //Pass this to RouteUrl
    document.location.href="@Url.RouteUrl("Category", new { categoryId=:parentId , SeName = "TEMP1"})";
    
  }
This is giving error as invalid character. I tried in many ways to pass parameter but no use.
Please please help. Thanks.

Thanks,
Amita
11 years ago
Use string placeholders when generating category URL.

Download nopCommerce 2.50 here (not the latest version). And have a look at \Presentation\Nop.Web\Views\Common\LanguageSelector.cshtml file in order to get an idea.

P.S. Do not forget to remove new { categoryId = @"\d+" } constraint for Category route
in \Presentation\Nop.Web\Infrastructure\RouteProvider.cs file
11 years ago
Thanks for a prompt reply.
As you said, I downloaded older version of nopcommerce & now my function looks like..
function searchProducts(){    
    var selectedLocation = document.getElementById('Location');      
    var parentId = selectedLocation.options[selectedLocation.selectedIndex].value;    
    var changeCatActionUrl = '@Url.RouteUrl("Category", new { categoryId = "categoryplaceholder" , SeName = "categoryplaceholder1" })';
    changeCatActionUrl = changeCatActionUrl.replace("categoryplaceholder", parentId);
    changeCatActionUrl = changeCatActionUrl.replace("categoryplaceholder1", "TEMP1");
    setLocation(changeCatActionUrl);
  }

Required functionality is on click of button which is at left side, middle page should get displayed with selected Products.
Now javascript is not giving error but middle page is not getting loaded at all. So problem is not yet solved.
Can you please help.

Also can you give links for:
1. Understanding Nopcommerce architecture
2. Code for demo site

Thanks,
Amita
11 years ago
Amita wrote:
Now javascript is not giving error but middle page is not getting loaded at all. So problem is not yet solved.
Can you please help.

Sorry. I'm quite busy with other tasks now and don't have an opportunity to test it further.

Amita wrote:
Also can you give links for:
1. Understanding Nopcommerce architecture
2. Code for demo site

1. All available documentation is here
2. What code? Demo site uses the latest version of nopCommerce (2.65 right now)
11 years ago
I am stuck as javascript is not loading product page. Kindly check when you get free time?

Anyways.. By Code.. What I meant was.. Can you please forward the link to download source code by which demo site was developed? Is that is available?
11 years ago
Amita wrote:
Anyways.. By Code.. What I meant was.. Can you please forward the link to download source code by which demo site was developed? Is that is available?

Please see my post above. It uses the latest version which can be downloaded here
11 years ago
Yes Thanks. I have downloaded the latest version.
Now can you please help me with the problem I am still facing...
Giving example....

Requirement is: Change Category dropdown & on click of button display only products related to that Category in the middle.

So in CategoryNavigation.chtml I have added a button & on click of that button called a javascript function in which I have written:

var mainStr ='@Url.RouteUrl("Category", new { categoryId="18" ,  SeName = "test1" })';  
window.location.href = mainStr;        

//I want to pass this categoryId as a parameter (which is hardcoded to 18 right now) depending upon value selected in Category dropdown.

With hardcoding the value its working fine but when I am taking this as parameter as per your previous post; its not working. Its not giving error but product page is not getting displayed.

What am I missing? I am stuck. Help is much appriated.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.