asp.net mvc image path and virtual directory

后端 未结 4 1792
死守一世寂寞
死守一世寂寞 2021-02-11 02:59

I know this has to be a duplicate, but I\'ve been wading through the hordes of information on this and I can\'t get it work.

I\'m trying to get a site working on a clien

4条回答
  •  耶瑟儿~
    2021-02-11 03:44

    You should use the routing to resolve your URLs.

    Personally I like to follow the best practices guide here to:

    Create Extension methods of UrlHelper to generate your url from Route

    You'll likely want an extension method for these static images you have:

    public static string StaticImage(this UrlHelper helper, string fileName)
        {
            return helper.Content("~/static/images/{0}".FormatWith(fileName));
        }
    

    then you can do:

    " />
    

提交回复
热议问题