문제

This sounds like a simple enough question, but can't find the answer for the life of me. How does one convert a root-relative url (~/my/path) to a virtual path (/mywebsite/my/path) in the Controller and/or Model?

On a view it's easy enough to do, just call @Url.Content("~/my/path/"). And getting the physical path in the controller is just as easy using Server.MapPath("~/my/path"). But I can't figure out how to get the virtual path in the controller.

My main issue is that I have a root-relative path of an image that I will be passing to a JSON object that will be returned. In most cases this will be read by javascript and put on the page somewhere, and I can't use @Url.Content in my javascript code. Also, in some instances this JSON object will be used by an external application that won't understand what the ~ means.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top