C# 动态拾取目录文件夹

C# 动态拾取目录文件夹,c#,asp.net-mvc,umbraco7,C#,Asp.net Mvc,Umbraco7,我需要用特定docType属性值设置的文件夹名称替换硬编码的文件夹名称,这是我的部分视图页面代码 @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ string folderPath = Server.MapPath("/media"); string[] files = Directory.GetFiles(folderPath + "/1039"); } @foreach (string item in files){

我需要用特定docType属性值设置的文件夹名称替换硬编码的文件夹名称,这是我的部分视图页面代码

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{
    string folderPath = Server.MapPath("/media");
    string[] files = Directory.GetFiles(folderPath + "/1039");
}
@foreach (string item in files){
     <img src="/media/1039/@Path.GetFileName(item)" />
}  
@继承Umbraco.Web.Mvc.UmbracoTemplatePage
@{
字符串folderPath=Server.MapPath(“/media”);
string[]files=Directory.GetFiles(folderPath+“/1039”);
}
@foreach(文件中的字符串项){
}  
我尝试了以下方法,但我认为它遗漏了一些东西

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    string folderPath = Server.MapPath("/media");
    string[] files = Directory.GetFiles(folderPath + "/@Model.Content.GetPropertyValue("placeID")");
}
@foreach (string item in files){
    <img src="/media/@Model.Content.GetPropertyValue("placeID")/@Path.GetFileName(item)" />
} 
@继承Umbraco.Web.Mvc.UmbracoTemplatePage
@{
字符串folderPath=Server.MapPath(“/media”);
string[]files=Directory.GetFiles(folderPath+“/@Model.Content.GetPropertyValue(“placeID”)”);
}
@foreach(文件中的字符串项){
} 
由(@MrMarsRed)解决,下面是正确的代码, 他的回答是,

使用此字符串时,您没有达到预期效果:

"/@Model.Content.GetPropertyValue("placeID")"
由于您位于C代码块中的一个字符串内部,因此@Model没有特殊意义(即,它实际上是以这种方式解释的,而不是作为表达式进行计算)。你想要这样的东西:

string[] files = Directory.GetFiles(folderPath + "/" + Model.Content.GetPropertyValue("placeID"));
这是最后的代码,它工作得很好

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        string folderPath = Server.MapPath("/media");
        string[] files = Directory.GetFiles(folderPath + "/" + Model.Content.GetPropertyValue("placeID"));
    }
    @foreach (string item in files){
        <img src="/media/@Model.Content.GetPropertyValue("placeID")/@Path.GetFileName(item)" />
    } 
@继承Umbraco.Web.Mvc.UmbracoTemplatePage
@{
字符串folderPath=Server.MapPath(“/media”);
string[]files=Directory.GetFiles(folderPath+“/”+Model.Content.GetPropertyValue(“placeID”);
}
@foreach(文件中的字符串项){
} 

如果您想回答自己的问题,也可以,但请提供此代码如何解决问题的说明。我已编辑了我的答案,并提供了此代码如何解决问题的说明,我希望这足够好,谢谢