javascript - .Net Core Get 不被击中

标签 javascript c# asp.net-core .net-core asp.net-core-mvc

Net Core MVC 并试图让我的应用程序读取文本文件,但是当我单击我的获取按钮时它不会激活相应的 IActionResult,我可能做的事情显然是错误的,因此我们将不胜感激。这是我的 View 和 Controller 的相关代码。

查看

 @{
 ViewData["Title"] = "Home Page";
 }

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Please Upload An Excel File.</p>
    <input type="file" name="datafile" 
           style="margin-left: 10px; margin-top: 15px; vertical-align: top;
                  font-size:18px; background-color: white; margin-left:160px;
                  margin-top:15px; width:250px; height:40px /">
</div>

<form method="get" asp-controller="Home" asp-action="Log">
    <div class="form-group">
        <p>Read</p>
        <input type="button" value="Read" />
    </div>
</form>

Controller :

[HttpGet]
public IActionResult Log()
{
    var webRoot = _env.WebRootPath;
    var file = Path.Combine(webRoot, "Output,txt");
    //var lines = System.IO.File.ReadAllText()
    System.IO.File.ReadAllText(file);
    return Content(file);
 }

提前致谢

最佳答案

你应该为按钮使用提交类型

   <input type="submit" value="Read" />

但我建议您将操作更改为 HttpPost

关于javascript - .Net Core Get 不被击中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57555260/

相关文章:

javascript - 如何在加载 promise 对象时添加加载动画?

javascript - Nodejs 比较两个不同的 Excel 文件并发现它们的差异

c# - ASP.NET Core - 如何在另一个 Controller 中重用在一个 Controller 中创建的方法?

c# - 在自定义配置部分 app.config 中定义重复键值

c# - LINQ To SQL - 获取已运行的 SQL

.net - Razor 页面可以放在除 Pages 之外的任何其他目录中吗?

c# - 通过 IHttpClientFactory 忽略 SSL 连接错误

javascript - 回溯问题 - 不知道如何做到这一点

javascript - 如何在javascript中从列表中的HTML保存多个文本对象

c# - ServiceStack Redis 什么是 urn