前端传递超长参数,前端与后端对应处理
目录
前端传递超长参数,前端与后端对应处理
当前端需要给后端传递对象集合,通常对象集合会很长,这样传递到后端时是接收不到相应参数的值的,因为被屏蔽了。
一般会报错,,URL参数过长,或者接口直接302,,根本访问不到接口
长字符串传值,前端用encodeURIComponent编码,后端用HttpUtility.UrlDecode解码
前端:encodeURIComponent为jquery自带的编码方式
var object = { "Id": id, "Description": Content };
$.post('.../Admin/Content/ModifyContent',
{ str: encodeURIComponent(JSON.stringify(object)), },
function (data) {
})
后端接收:
public void ModifyContent( string str)
{
//长字符串传值,前端用encodeURIComponent编码,后端用HttpUtility.UrlDecode解码
var result = HttpUtility.UrlDecode(str);
var model = JsonMapper.ToObject<WebContentShiftViewModel>(result);
}
此贴为记录贴,欢迎大家提供更多解决方式。
另外一种解决方式,有可能行,在web.config中的加入
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" executionTimeout="120" maxRequestLength="1024000000"/>
</system.web>