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.
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
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
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.