我在MVC中有一个错误,当我传递参数'&'未能得到以下内容时。我将如何在此示例中显示?
public IActionResult Create(int? idTrabalhador, [FromQuery]string GridState{}
视图
var lnk = "@Url.Action("Create" , new { idTrabalhador = "{#KeyTrabalhador}", GridState = "{#GRID_STATE}" })";
lnk = lnk.replace(encodeURIComponent("{#KeyTrabalhador}"), 0);
lnk = lnk.replace(encodeURIComponent("{#GRID_STATE}"), JSON.stringify(state));
http://localhost:58185/TrabalhadorPincodes/Create?idTrabalhador=0&GridState={"filter":{"NomeTrabalhador":"nuno","Estado":"0"},"sorter":[],"currentPage":0}
\ n \ n \ n:\“0 \”},\“分拣机\”:[],\“ currentPage \“:0}”
完善!!!
但
http://localhost:58185/TrabalhadorPincodes/Create?idTrabalhador=0&GridState={"filter":{"NomeTrabalhador":"&","Estado":"0"},"sorter":[],"currentPage":0}
model => GridState =“{\”filter \“:{\”NomeTrabalhador \“:\”“
需要帮忙!!!
当您通过GET方法发送http请求时,浏览器将&
解释为url的一部分。
处理此问题的一种方法是使用Server.UrlEncode
对参数进行urlEncode这也意味着您需要解码控制器中的参数。
另一种解决方案是发布值,使它们不是URL的一部分,但您需要确定这是否合适。
因为'encodeURIComponent'只能在纯文本中工作,我正在做的是创建一个复合对象很快就行不通。一旦构造了对象,我就不得不使用'encodeURIComponent'
filter.NomeTrabalhador = encodeURIComponent($('#NomeTrabalhador')。val());