c# - How to Translate this Image Source into Url.Content? -
i have following image rendered way.
<img src="../../../..@model.floorplan.floor_plan_image_path@model.floorplan.floor_plan_image_filename" alt=""/>
i want if possible it's src attribute changed url.content.
what have tried problem treats model string:
<img src="@url.content("~/model.floorplan.floor_plan_image_path@model.floorplan.floor_plan_image_filename")" alt=""/>
can me?
the value of path , filename follows:
model.floorplan.floor_plan_image_path = "/content/uploads/floorplans/00004601/" model.floorplan.floor_plan_image_filename = "testfloorplan.png"
i found myself in situation need format string on view, made extension method this, rid of string.format
's on every view.
public static class urlhelpers { public static string content(this urlhelper urlhelper, string formatpath, params object[] args) { return urlhelper.content(string.format(formatpath, args)); } }
it formats specified path, nothing going on, calling bit nicer read.
@{ var path = model.floorplan.floor_plan_image_path; var imagename = model.floorplan.floor_plan_image_filename; } <img src="@url.content("~{0}{1}", path, imagename)"/>
Comments
Post a Comment