C# 带有<;图>;在ASP.NETMVC中

C# 带有<;图>;在ASP.NETMVC中,c#,asp.net-mvc,C#,Asp.net Mvc,我正在用C#和.NETFramework 4.7开发一个ASP.NETMVC5应用程序 我想用这个: <input type="file" name="file-5[]" id="file-5" class="inputfile inputfile-4" data-multiple-caption="{count} files selected" multiple /> <label for="file-5"><figure><svg xmlns="ht

我正在用C#和.NETFramework 4.7开发一个ASP.NETMVC5应用程序

我想用这个:

<input type="file" name="file-5[]" id="file-5" class="inputfile inputfile-4" data-multiple-caption="{count} files selected" multiple />
<label for="file-5"><figure><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg></figure> <span>Chose file&hellip;</span></label>
我尝试了以下方法,但在
@Html.LabelFor(m=>m.File)
中不正确:

@Html.LabelFor(m=>m.File{
“选择文件&hellip;”
})
@Html.TextBoxFor(m=>m.File,新的{type=“File”,@class=“inputfile-inputfile-4”,数据\多个\标题=“{count}所选文件”})

问题在于
您的代码有语法error@AluanHaddad您没有说:“guest where…”您的问题是标签显示不正确,文件属性在发布到操作时没有获得值吗?首先,您可以绕过LabelFor处理程序执行
。至于你的模型没有在行动中得到满足。您确定数据已发送到服务器吗?您的模型/操作是什么样子的(更具体地说,您如何尝试访问发布的文件?)。在您的情况下,您不能使用
LabelFor()
——该方法仅生成
文本
(文本将被编码)。对于文件输入,您需要创建自己的自定义扩展名方法(或手动生成),如果属性是
HttpPostedFileBase file
,那么它必须是
name=“file”
(您的
@Html.TextBoxFor(m=>m.file,…)正确生成的

@Html.LabelFor(m => m.File)
@Html.TextBoxFor(m => m.File)
@Html.LabelFor(m => m.File, {
                   "<figure><svg xmlns='http://www.w3.org/2000/svg' width='20' height='17' viewBox='0 0 20 17'><path d='M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z'/></svg></figure> <span>Chose file&hellip;</span>"
               })
@Html.TextBoxFor(m => m.File, new { type = "file", @class = "inputfile inputfile-4", data_multiple_caption = "{count} files selected" })
<input type="file" name="file-5[]" id="File"