.Net Core Get 不被击中

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);

 }


慕虎7371278
浏览 116回答 1
1回答

摇曳的蔷薇

您应该使用按钮的提交类型&nbsp;&nbsp;&nbsp;<input&nbsp;type="submit"&nbsp;value="Read"&nbsp;/>但我建议你将操作更改为 HttpPost
打开App,查看更多内容
随时随地看视频慕课网APP