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/