Hey there, I'm encountering an issue with calling an action result in my controller that contains parameters. Whenever one of these parameters has a special character like #, the string parameters are not including the # sign and all subsequent parameters are set to null.
Here is the JavaScript code I'm using to call the action result:
<script type="text/javascript">
$(document).ready(function () {
$('#btnExport').unbind().click(function () {
var url = @Url.Content("~/BankStatement/ExportBankStatementSummary") +
"?legalName=" + '@ViewBag.LegalName' +
"&dba=" + '@ViewBag.DBA' +
"&contactPerson=" + '@ViewBag.ContactPerson' +
"&address=" + '@ViewBag.Address' +
"&period=" + '@ViewBag.Period' +
"&totalHeading=" + '@ViewBag.TotalHeading';
window.location = url;
});
});
</script>
This is the action result being called by the above JavaScript:
public ActionResult ExportBankStatementSummary(string legalName, string dba,
string contactPerson, string address,
string period, string totalHeading)
{
ViewBag.LegalName = legalName;
ViewBag.DBA = dba;
ViewBag.ContactPerson = contactPerson;
ViewBag.Address = address;
ViewBag.Period = period;
ViewBag.TotalHeading = totalHeading;
...
The problem arises when any parameter in the action result contains a special character (# in this case), causing that parameter and the following parameters to become null.
For instance, if the address is "Street # 2", then the address parameter becomes "Street" and the period and totalHeading parameters become null.
Any assistance on resolving this issue would be greatly appreciated.
Thank you in advance.
[I do not believe this question is a duplicate, as the other question referenced discusses different details and does not fully cover the answer to this particular issue.]