Asp.net-Mvc-2

我應該在 MVC 視圖中使用 Url.Content() 還是 ResolveUrl()?

  • March 10, 2010

在建構這樣的程式碼時:

<script type="text/javascript" src="<%=ResolveUrl("~/js/js.js")%>"></script>

要麼

<input type="image" src="<%=ResolveUrl("~/img/submit.png")%>" />

我應該使用Url.ContentorResolveUrl()嗎?有什麼不同?

如果您在 MVC 應用程序中使用 IIS URL 重寫,例如在內部將<http://yoursubdomain.example.com/MyController/MyAction>視為<http://hosted.example.com/yoursubdomain/MyController/MyAction>,則 Url.Content( ) 將生成正確的子域相關連結。ResolveUrl() 在這種情況下會生成一個不正確的連結。

引用自:https://stackoverflow.com/questions/2418050