Visual Studio调试会立即停止在MVC中上传文件吗? [英] Visual Studio debugging stop immediately on file upload in mvc?

查看:94
本文介绍了Visual Studio调试会立即停止在MVC中上传文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用Visual Studio 2019 Enterprise进入.NET Core MVC.

So I'm trying to get into .NET Core MVC using Visual Studio 2019 Enterprise.

我尝试遵循Microsoft自己的 AboutController.cs 和在Microsoft网站上找到的方法:

I tried to follow a fairly simple example from Microsofts own documentation. After setting up the code, I have the template project that they give you with MVC. So on the "About" page I have the following controller class AboutController.cs with the method found on Microsofts website:

[HttpPost("UploadFiles")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
    long size = files.Sum(f => f.Length);
    string filePath = Path.GetTempFileName();

    if (files.Count > 0)
    {
        IFormFile file = files[0];
        if (file.Length > 0)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
        }
    }

    return View();
}

唯一的大"区别是我返回视图,而不是确定",因为我对此并不感兴趣.我想修改我正在查看的视图,而不是使用全新的视图(也许我误解了MVC的工作原理?).

The only "big" difference is that I return the view, not an "Ok" because I'm not really interested in that. I want to modify the view I'm looking at not go to a completely new view (maybe I'm misunderstanding how MVC works?).

现在我的HTML看起来像这样:

Now my HTML looks like this:

<form method="post" enctype="multipart/form-data" asp-controller="About" asp-action="Post">
    <div class="form-group">
        <div class="col-md-10">
            <p>Upload one image using this form:</p>
            <input type="file" name="files">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-10">
            <input type="submit" value="Upload">
        </div>
    </div>
</form>

这将生成表格,也可以在前面链接的文档中看到.当我单击浏览"按钮查找图片时,它工作正常,当我单击打开"以便上载时,Visual Studio调试器将立即停止运行.我看不到任何地方的错误.

This produces the form, also as seen in their documentation linked earlier. When I click the "Browse" button to find a picture, it works fine and when I click "Open" so I can upload it, the Visual Studio debugger stops running immediately. No error anywhere that I can see.

任何想法会导致这种行为吗?

Any idea what causes this behaviour?

更新1

似乎只是调用return View();表现出相同的行为,Nuget说它是AspNetCore.Mvc 2.1.1

It appears that just calling return View(); exhibits the same behaviour and Nuget says it's AspNetCore.Mvc 2.1.1

更新2

结果发现调试器在此特定实例中无法使用名为"Brave"的浏览器,该浏览器是我使用的Chrome浏览器(如果忘记提及的话)

Turns out the debugger does not work in this particular instance with the browser called "Brave" which is a chromium browser that I use (which If forgot to mention)

推荐答案

具体而言,此行为归因于浏览器问题,而不是通常的Visual Studio.根据文章和本文,使用这种情况下的勇敢"浏览器和Yandex等浏览器通常会观察到这种行为.有时甚至Chrome也会显示这种行为,但并不一致(至少这是我观察到的).

This behavior in specific has been attributed to a browser problem and not Visual Studio in general. As per this article and this article, this behavior was generally observed when using browsers like Brave in this case and Yandex. Sometimes even Chrome shows this behavior but it is not consistent (at least that is what I have observed).

可能的解决方案是将您的浏览器类型更改为使用理想的浏览器,例如Chrome,Firefox或Edge.

A possible solution would be changing your browser type to use ideal browsers like Chrome, Firefox or Edge.

这篇关于Visual Studio调试会立即停止在MVC中上传文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆