質問

In MVC, the ~ at the top of a server side directory reference should be converted to the root of the website.

I have the following lines at the top of my cshtml file:

<link rel="STYLESHEET" type="text/css" href="~/codebase/dhtmlxgrid.css">
<script src="~/codebase/dhtmlxcommon.js"></script>
<script src="~/codebase/dhtmlxgrid.js"></script>
<script src="~/codebase/dhtmlxgridcell.js"></script>
<script src ="~/IactexScripts/WorkOrderAdd.js"></script>

When the code is run, I get the following in my output sent to the browser:

<link rel="STYLESHEET" type="text/css" href="/codebase/dhtmlxgrid.css">
<script src="/codebase/dhtmlxcommon.js"></script>
<script src="/codebase/dhtmlxgrid.js"></script>
<script src="/codebase/dhtmlxgridcell.js"></script>
<script src ="~/IactexScripts/WorkOrderAdd.js"></script>

Notice that the ~ was properly translated to nothing, since this was running at the root, while on the last line, it was not translated, and as a result, the file was not found.

This is important since this page will not always run from the root of the website.

Any help would be appreciated.

役に立ちましたか?

解決

tereško is right! The leading space was the cause of the failure. Thanks so much!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top