如何将此图像源转换为Url.Content?
我有以下图像以这种方式呈现。
我希望如果可能的话,它的src属性将被更改为Url.Content。
我试过的是这个,但我的问题是它将我的模型视为字符串:
谁能帮我?
Path和Filename的值如下:
Model.FloorPlan.Floor_Plan_Image_Path =“/ Content / Uploads / FloorPlans / 00004601 /”Model.FloorPlan.Floor_Plan_Image_Filename =“testfloorplan.png”
我发现自己处于这样一种情况,我需要在任何视图上格式化字符串,所以我为此做了一个扩展方法,只是为了摆脱每个View上的String.Format
。
public static class UrlHelpers { public static string Content(this UrlHelper urlHelper, string formatPath, params object[] args) { return urlHelper.Content(String.Format(formatPath, args)); } }
它只是简单地格式化指定的路径,没有什么进展,但是调用它会更好看。
@{ var path = Model.FloorPlan.Floor_Plan_Image_Path; var imageName = Model.FloorPlan.Floor_Plan_Image_Filename; }
尝试
我想我明白你的意思。 试试这个: