Net Core MVC 并試圖讓我的應(yīng)用程序讀取文本文件,但是當(dāng)我單擊“獲取”按鈕時,它不會激活相應(yīng)的 IActionResult,我可能做了一些明顯錯誤的事情,所以任何幫助將不勝感激。這是我的視圖和控制器的相關(guān)代碼。看法 @{ 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貢獻(xiàn)1793條經(jīng)驗 獲得超6個贊
您應(yīng)該使用按鈕的提交類型
<input type="submit" value="Read" />
但我建議你將操作更改為 HttpPost
- 1 回答
- 0 關(guān)注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消