为了账号安全,请及时绑定邮箱和手机立即绑定

.Net Core Get 不被击中

.Net Core Get 不被击中

C#
慕虎7371278 2023-09-09 17:30:12
Net Core MVC 并试图让我的应用程序读取文本文件,但是当我单击“获取”按钮时,它不会激活相应的 IActionResult,我可能做了一些明显错误的事情,所以任何帮助将不胜感激。这是我的视图和控制器的相关代码。看法 @{ 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>控制器:[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); }
查看完整描述

1 回答

?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

您应该使用按钮的提交类型

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

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


查看完整回答
反对 回复 2023-09-09
  • 1 回答
  • 0 关注
  • 42 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信