我只是想知道將參數傳遞給包含您不希望傳遞給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 –