URL Encoding of url.action using RAW to help with encoding MVC and Javascript

var Url = ‘@Html.Raw(Url.Action(“EditMonthlyQuota”, “ContractMod”, new { contrId = Model.ContrId, FundId = Model.ContrFundId, OAQuotaId = Model.OaQuotaHdrId, Model.ContrYrNo }))’;

 

 // Encode the MVC Action Result, but use RAW to avoid getting & in the url.
 var url =
 '@Html.Raw(Url.Action("PrintPayrollReports", "Print", new { payrollId = "_payrollId_" }))';
 // Once URL is encoded, a simple trick is to replace place holders for real values
 var finalUrl = url.replace('_payrollId_', _payrollId_);
 
 $.ajax({
 type: 'Post',
 dataType: "json",
 url: finalUrl,
 contentType: 'application/json',
 data: '',
 success: function (message) {
 $.unblockUI();
 debugger;
 if (message) {
 $('#errorMsg').find('.modal-body').text(message);
 $('#errorMsg')
 .modal({
 backdrop: false,
 keyboard: true,
 });
 }
 },
 error: function (XMLHttpRequest, textStatus, errorThrown) {
 $.unblockUI();
 debugger;
 $('#errorMsg').find('.modal-body').text(errorThrown);
 $('#errorMsg')
 .modal({
 backdrop: false,
 keyboard: true,
 });
 }
 });

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s