Jackington
Jackington

Reputation: 127

.Net Core Get not being hit

Net Core MVC and trying to get my application to read a text file however when I click my get button it doesn't activate the corresponding IActionResult, I'm probably doing something obviously wrong so any help would be much appreciated. Here's the relevant code for my view and controller.

View

 @{
 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);
 }

Thanks in advance

Upvotes: 1

Views: 159

Answers (1)

Tony
Tony

Reputation: 20102

You should use submit type for button

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

But I would recommend you change your action to HttpPost

Upvotes: 4

Related Questions