如何使用razor视图在MVC 4中打开文件夹对话框 [英] How do I open a folder dialog in MVC 4 with razor view

查看:83
本文介绍了如何使用razor视图在MVC 4中打开文件夹对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按钮单击时打开文件夹对话框,并在变量中需要该路径,以便我可以使用它来提取所选文件夹中的所有图像。

我正在使用MVC 4用剃刀视图。请查看cshtml页面。

我知道如何打开文件对话框,但需要一个文件夹对话框。



我有什么尝试过:



这是用于文件对话框,但需要选择一个文件夹



< div>

选择图像< input type =filename =file/>

< input type =submitvalue =上传图片name =命令/>

< br />< br />

文件名= @ ViewBag.filename

< br />

ImageUrl = @ ViewBag.ImageURL

< / div>

解决方案

< blockquote>如果要上传整个文件夹,则需要将多个目录属性添加到文件中输入:

< input type =   file  name =   fi le accept =   image / *多个目录webkitdirectory mozdirectory /> 



注意:您目前还需要包含目录属性的供应商前缀版本。

< a href =https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory> HTMLInputElement.webkitdirectory - Web API | MDN [ ^ ]



这是HTML标准的非官方扩展。它适用于Edge,Firefox,Chrome和Opera。它不适用于任何版本的IE或Safari,也不适用于移动浏览器。

可以我使用...从文件输入中选择目录 [ ^ ]



在不支持它的浏览器中,多个属性将确保用户仍然可以选择要上传的多个文件。



在任何一种情况下, Request.Files 集合都将包含<每个发布文件的code> HttpPostedFile 。


I want to open a folder dialog on a button click and need that path in a variable so that i can use it to extract all the images in the selected folder.
I am using MVC 4 with razor view . please rply for cshtml page.
I know how to open a file dialog but need a folder dialog.

What I have tried:

This is for file dialog but need to select a folder instead

<div>
Select Image <input type="file" name="file" />
<input type="submit" value="Upload Images" name="Command" />
<br /><br />
Filename = @ViewBag.filename
<br />
ImageUrl = @ViewBag.ImageURL
</div>

解决方案

If you want to upload an entire folder, then you need to add the multiple and directory attributes to the file input:

<input type="file" name="file" accept="image/*" multiple directory webkitdirectory mozdirectory />


NB: You currently need to include the vendor-prefixed versions of the "directory" attribute as well.
HTMLInputElement.webkitdirectory - Web APIs | MDN[^]

This is an unofficial extension to the HTML standard. It works in Edge, Firefox, Chrome, and Opera. It doesn't work in any version of IE or Safari, or in mobile browsers.
Can I use... Directory selection from file input[^]

In browsers that don't support it, the multiple attribute will ensure that users can still select multiple files to upload.

In either case, the Request.Files collection will contain an HttpPostedFile for each posted file.


这篇关于如何使用razor视图在MVC 4中打开文件夹对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆