在Firefox Developer Edition

时间:2018-01-25 12:30:50

标签: c# asp.net-mvc visual-studio-2017 firefox-developer-tools

我正在使用Firefox Developer Edition和Visual Studio 2017来开发ASP.NET MVC应用程序。我正在使用表单将数据发送到我的应用程序。我可以看到数据进入Visual Studio,但是当我查看Firefox开发人员工具中的“网络”部分时,会列出POST请求,但它显示为空。

  

“此请求没有标头”

firefox

visual-studio

如果我尝试使用Google Chrome进行调试,那么我甚至看不到列出的POST请求。

chrome

以下是视图的操作。

public ActionResult New()
{
    var membershipTypes = _context.MembershipTypes.ToList();
    var viewModel = new NewCustomerViewModel
    {
        MembershipTypes = membershipTypes
    };

    return View(viewModel);
}

以下是视图的表单。

@using (Html.BeginForm("Create", "Customers"))
{
    <div class="form-group">
        @Html.LabelFor(m => m.Customer.Name)
        @Html.TextBoxFor(m => m.Customer.Name, new { @class = "form-control" })
    </div>

    <div class="form-group">
        @Html.LabelFor(m => m.Customer.BirthDate)
        @Html.TextBoxFor(m => m.Customer.BirthDate, new { @class = "form-control" })
    </div>

    <div class="checkbox">
        <label>
            @Html.CheckBoxFor(m => m.Customer.IsSubscribedToNewsletter) Subscribed to Newsletter?
        </label>
    </div>

    <div class="form-group">
        @Html.LabelFor(m => m.Customer.MembershipTypeId)
        @Html.DropDownListFor(m => m.Customer.MembershipTypeId, new SelectList(Model.MembershipTypes, "Id", "Name"), "Select Membership Type", new { @class = "form-control" })
    </div>

    <button type="submit" class="btn btn-primary">Save</button>
}

这是POST方法的操作。

[HttpPost]
public ActionResult Create(Customer customer)
{
    return View();
}

因为我目前没有在视图中返回任何内容,所以我有一个断点用于返回。但是,如果我继续调试,我会收到服务器错误,正如预期的那样。

  

“未找到视图'创建'或其主文件或没有查看引擎   支持搜索的位置。“

但是,此时,当我在浏览器中检查数据时,POST方法会填充数据。

firefox2

这是为什么?即使在将视图返回给客户端之前,我是否应该无法看到发送到服务器的POST方法标头数据?我正在运行我的localhost上的所有内容,包括数据库。

我希望在断点处看到我发送到服务器的表单数据,如下所示。我可以在Chrome中看到相同内容,但只能在返回视图后才能看到。

firefox-form

1 个答案:

答案 0 :(得分:1)

  

“找不到视图'创建'或其主人,或者没有视图引擎支持搜索的位置。”

这是因为缺少Create.cshtml

您设置它的方式需要两个视图:

public ActionResult New()
{
    return View(viewModel);          // New.cshtml
}

[HttpPost]
public ActionResult Create(Customer customer)
{
    return View();                   // Create.cshtml
}

至于Firefox在F12中没有完全显示请求 - Firefox和其他浏览器并不完美。这很烦人,但我不知道任何修复。

也许您应该将其作为错误报告给Mozilla?

相关问题