asp.net
  • asp.net-mvc
  • razor
  • 2012-09-04 30 views 0 likes 
    0

    我有一個這樣的網格列:沒有找到圖片在MvcHtmlString.Create()

    gridSpecs.Column(header: "", columnName: "", 
        format: (spec) => MvcHtmlString.Create(string.Format(
        "<a href='' onclick='RemoveEquipment({0}); return false;'><img src='~/Images/Delete.png' alt='x' /></a>", 
        spec.Equipment.EquipmentId))), 
    

    它工作正常,除了圖像是找不到的。

    enter image description here

    事實上,鉻控制檯報告:Failed to load resource: the server responded with a status of 404 (Not Found).

    但是,如果我把那個確切的代碼在網頁中的其他地方,對自己,圖像將顯示:

    <img src='~/Images/Delete.png' alt='x' /> 
    

    任何想法爲什麼它不會顯示在MvcHtmlString.Create()方法內?

    回答

    1

    Tilde標誌不會在客戶端的html標籤中運行。因此,要麼輸入確切的絕對URL,要麼從src中刪除~/

    希望這會有所幫助。

    +1

    刪除'〜/'沒有用,但用'../../'做了。謝謝! –

    +0

    @BobHorn,是的,因爲現在圖像文件夾是存在於兩個級別的目錄中。 –

    相關問題