【问题标题】:Errors with new MVC5 project in Visual Studio 2013.3Visual Studio 2013.3 中的新 MVC5 项目出错
【发布时间】:2014-12-10 19:07:14
【问题描述】:

想知道是否有其他人经历过这种情况,如果有,他们的解决方案是什么。在 Visual Studio 2013 中,我创建了一个新的 ASP.NET Web 应用程序,保留所有默认值

在下一个屏幕中,我选择 MVC,为 MVC 添加文件夹和核心引用,但不添加其他两个选项。身份验证保留在 Individual User Accounts 中,并且我已取消选中 Host in the cloud 选项,如下所示。

项目向导完成,在我做任何其他事情之前,我可以看到其中有 26 个错误。

消除这些错误的第一个修复是 Views\Account\ _SetPasswordPartial.cshtml_ChangePasswordPartial.cshtml 文件包含无效模型,因此我将其更改如下:

[我这里的项目名称是WebApplication1,替换成你自己的值]

在 _SetPasswordPartial.cshtml 中: 从@model WebApplication1.Models.ManageUserViewModel@model WebApplication1.Models.SetPasswordViewModel

在文件 _ChangePasswordPartial.cshtml 中: 从@model Microsoft.AspNet.Identity.ManageUserViewModel 到@model WebApplication1.Models.ChangePasswordViewModel

这使我减少到 4 个错误,分布在 4 个文件中

1。 第 68 行,ManageController.cs

return View(linkedAccounts);

视图 RemoveLogin 不存在

2,3。 有两个错误 _SetPasswordPartial.cshtml_ChangePasswordPartial.cshtml 抱怨无法解决 Manage 操作,但是当我在浏览器中调试和访问这些 URL 时它们工作正常,所以我怀疑它们在某处的路由表中。我已经安装了 R#,所以如果是这种情况,有时可能会出错。

4。 最后一个是_RemoveAccountPartial.cshtml 在第 15 行有一个错误,它抱怨在 Account 控制器中没有 Disassociate 操作,据我所知,这与删除应用程序的其他身份验证提供程序有关。

现在我可以通过添加所需的代码来解决所有这些问题,但我觉得模板不能开箱即用。是否有可用的新模板,或者有没有人写过关于如何在您开始正常工作之前让您的模板嗡嗡作响的规范文章?

编辑 2014-11-13 我刚刚应用了 VS2013.4,这些问题似乎已作为其中的一部分得到修复。如果这对人们来说是个问题,那么我建议应用该更新。

【问题讨论】:

  • 我没有任何帮助,但确实在一个干净的项目(VS 2013 Ultimate(已安装所有补丁)、MVC 5、.NET 4.5.1)上确认了问题。
  • 我在项目中搜索了 _SetPasswordPartial,但什么也没找到,_ChangePasswordPartial 也是如此。也许这些只是一些遗留的文件?请注意,在 Manage 下有一个 SetPassword 视图,其他视图相同。
  • _RemoveAccountPartial.cshtml 似乎在 ManageLogins.cshtml 中有匹配的代码(在管理下),所以我认为这也可以删除

标签: c# asp.net asp.net-mvc razor asp.net-mvc-5


【解决方案1】:

我不知道这些问题的根本原因是什么,但是在玩了这个项目之后,以下似乎使它进入了一个一致的状态:

  1. 删除Views\Account\_SetPasswordPartial.cshtml
  2. 删除Views\Account\_ChangePasswordPartial.cshtml
  3. 删除Views\Account\_RemoveAccountPartial.cshtml

所有这些在Manage 控制器下都有对应项。最后:

  1. ManageController 中删除RemoveLogin() 操作方法。确保只删除 GET 方法(第 64 - 69 行),因为实际使用的是 POST 方法。登录列表由ManageLogins 操作呈现。

【讨论】:

  • 我认为删除这些部分肯定会破坏某些东西,但在第一次测试时它似乎工作正常。谢谢卡雷尔...
【解决方案2】:

发现这是一个已知问题: http://blogs.msdn.com/b/webdev/archive/2014/08/04/announcing-new-web-features-in-visual-studio-2013-update-3-rtm.aspx

  1. 当使用单独的身份验证从 MVC、WebAPI 或 SPA 模板创建默认 C# ASP.NET Web 应用程序时,生成的 Views\Account\ _SetPasswordPartial.cshtml 和 _ChangePasswordPartial.cshtml 文件包含无效模型。

在文件_SetPasswordPartial.cshtml中,

@model .Models.ManageUserViewModel 应改为: @model .Models.SetPasswordViewModel

在文件_ChangePasswordPartial.cshtml中,

@model Microsoft.AspNet.Identity.ManageUserViewModel 应改为: @model .Models.ChangePasswordViewModel

生成的 VB 项目也存在类似问题。

在文件_SetPasswordPartial.vbhtml中,

@ModelType ManageUserViewModel 应改为: @ModelType 设置密码视图模型

在文件_ChangePasswordPartial.vbhtml中,

@ModelType ManageUserViewModel 应改为: @ModelType 更改密码视图模型

【讨论】:

    【解决方案3】:

    我也在 VS2013 Ultimate Update#3 中确认了问题。在 Visual Studio 和 .NET Framework 部分下向 Microsoft Connect 提交错误报告。

    【讨论】:

    • 这应该作为评论而不是答案发布。谢谢
    • 虽然同意@Jakub 并附议您应该将其移至评论,但在您编辑它时,请附上提交内容的链接?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多