我只是想知道将参数传递给包含您不希望传递给URL的字符的URL的最佳做法。例如,我传递字符串/LM/W3SVC/7/ROOT
到URL,但我想通过它没有反斜杠,从而相似LMW3SVC7ROOT
将参数传递给URL ASP.NET MVC
我目前做到这一点是通过使用.Replace()
的方式。这是我目前使用的全部代码<a href="@Url.Action("Errors", new { id=item.Application.Replace("/", "").Replace(".", "")})"> @Html.DisplayFor(modelItem => item.Application) </a>
,它工作正常,但每隔一次又一次发出警告,所以我只是想知道这是否是实现它的正确方式。
'Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'
在此先感谢。
你应该URL编码它的反斜杠,或者是有特殊原因不想这样做? – ediblecode
'item.Application'的类型是什么?它是一个字符串吗? – ediblecode
不,没有理由不使用它,也许是因为缺乏知识,如果有的话。是的,这是一个字符串@jumpingcode –