我正在通过JSON向控制器发送一个参数,该参数包含和ampersand,并且在该字符之后,字符串被切断。一直在搜索数小时,找不到解决方案。
javascript
var url = '/Common/DownloadFile?fileName=Me&You.xlsx';
$.ajax({
type: 'POST',
url: url,
data: {},
success: function (data) {}
});
控制器
public ActionResult DownloadFile(string fileName)
{
// Here the param is coming in as 'Me'
// Code removed for clarity
}
在urls&需要逃脱,因为它用于添加
之类的新参数 http://hello.com"?fileName=Something&otherFileName=SomethingElse
您需要以这样的速度来逃避and和and and and and and and and and and。
/Common/DownloadFile?fileName=Me%26You.xlsx
这是有关URL参数逃避逃避and和url中的更多信息
ampersand用于在URL中分离参数。如果您希望Ampersand成为参数值的一部分,则需要使用Encodeuricomponent()的方法来进行UrlenCode。
在这种特殊情况下,我的编码版本& you.xslx将为me%26you.xlsx。如果您在Get请求中指定应用程序应获得预期值。