【问题标题】:Asp.net MVC button should open file dialogAsp.net MVC 按钮应该打开文件对话框
【发布时间】:2023-03-16 16:06:01
【问题描述】:

我想使用下面的按钮打开一个文件对话框来选择一个/多个单词文件。我还希望它像一个返回路径的方法,以便我可以读取/加载该数据。

<div>
    <div class="col-lg-6 col-md-6 col-sm-6">
        <img class="img-analyse" src="~/Content/open-file_icon.png">
        <button class="button-analyse"onclick="SelectFile">b</button>
    </div>
</div>

我该如何继续?我要注册一个动作事件吗? 对不起,我是 asp.net 的初学者。

【问题讨论】:

  • 你知道,这将在客户端执行,你实际上不能从 MVC 那里写,对吧?
  • 使用&lt;input type="file"&gt;
  • 我试过了,但后来我无法修改我的按钮以使其透明。如果我这样做,我在哪里可以获得文件路径?

标签: c# html asp.net-mvc button openfiledialog


【解决方案1】:

可以使用代理文件上传控制

$("#btnSelect").click(function() {
  var $input = $('<input type="file" />');
  $input.change(function() {
    console.log("selected file:" + $(this).val());
  });
  $input.trigger('click');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="col-lg-6 col-md-6 col-sm-6">
  <button class="button-analyse" id="btnSelect">select file</button>
</div>

这是给你的小提琴:http://jsfiddle.net/CSvjw/2034/

【讨论】:

  • 这段代码是你写的吗?在 bootstrap.js 或 bootstrap.min.js 中?
  • 在单独的.js文件中,为什么要在bootstrap.js或bootstrap.min.js中写代码,它们是库文件。
  • 好的,谢谢,我会试试的,我的 layout.cshtml 文件中已经有脚本行,所以应该没问题吧?
猜你喜欢
  • 2011-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-07
相关资源
最近更新 更多