Click here to Skip to main content
15,889,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have variable name

var vehiclename ="TVS STAR CITY+ (BS IV)-SMAG-SBT" like this this coming from dynamically by click event on pie charts that block name coming from database

now my problem is i have passed this variable as parameter
$.ajax({
datatype: "json",
Type: "Get",
url: baseUri + 'api/Purchases/BookingByVehicleName/?VehicleName=' + vehicleName,
success: function (data) {

}

},
error: function (jqXHR, textStatus, errorThrown) {

}
});
this is my control
[HttpGet]
[Route("BookingByVehicleName")]
public IEnumerable<object> BookingByVehicleName(string VehicleName) => bizPurchases.BookingByVehicleName(VehicleName);

now the issuse is parameters miss the specal character
orginal parameter cames from variable is "TVS STAR CITY+ (BS IV)-SMAG-SBT" when hits the controller the parameter value turns into "TVS STAR CITY (BS IV) SMAG SBT" here special character are missings

What I have tried:

i have changed data type string to char but its not working can u please help any for this
Posted
Updated 18-Sep-19 3:01am
Comments
F-ES Sitecore 18-Sep-19 9:06am    
In addition to encoding the text as shown in Solution 1, if you use the "data" attribute and put the vehicleName in there then jQuery will encode the text for you.

1 solution

The standard encodeURI() method that the framework uses for AJAX is skipping the '+'. I'm not sure why the '-' are getting stripped, though.

Try this:

JavaScript
url: baseUri + 'api/Purchases/BookingByVehicleName/?VehicleName=' + encodeURIComponent(vehicleName),


Documentation: encodeURIComponent() - JavaScript | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900