当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Errors with new MVC5 project in Visual Studio 2013.3

问题描述:

Wondering if anyone else has experienced this and what their solution was if so. In Visual Studio 2013 I create a new ASP.NET Web Application, leaving all the defaults as they are

In the next screen I pick MVC, adding folders and core references for MVC but not the other two options. Authentication is left at Individual User Accounts and I've unchecked the Host in the cloud option, as shown below.

The project wizard completes and I can see that there are 26 errors in it before I do anything else.

The first fix that removes a bunch of these errors is that the Views\Account\ _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml files contain invalid models so I change those as follows:

[My project name here is WebApplication1, substitute your own value]

In _SetPasswordPartial.cshtml:

From @model WebApplication1.Models.ManageUserViewModel to @model WebApplication1.Models.SetPasswordViewModel

In file _ChangePasswordPartial.cshtml:

From @model Microsoft.AspNet.Identity.ManageUserViewModel to @model WebApplication1.Models.ChangePasswordViewModel

That drops me down to 4 errors, spread across 4 files

1.

Line 68, ManageController.cs

return View(linkedAccounts);

The view RemoveLogin doesn't exist

2,3.

There are two errors _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml complaining about not being able to resolve the Manage action but when I debug and visit those URLs in the browser they work fine so I suspect they're in a route table somewhere. I have R# installed so sometimes that can be wrong if that's the case.

4.

The last one is that the _RemoveAccountPartial.cshtml has an error on line 15 where it complains about not having a Disassociate action in the Account controller, as far as I can ascertain this is to do with removing other authentication providers to the application.

Now I can fix all these by adding the required code but it just doesn't sit well with me that the templates don't work well out of the box. Are there fresh templates available or has anyone done the canonical write-up on how to get your template humming before you commence work properly on it?

EDIT 2014-11-13

I've just applied VS2013.4 and these issues appear to be fixed as part of it. If this is an issue for people then I suggest applying that update.

网友答案:

I do not know what is the root cause of these problems but after playing with the project the following seems to bring it to a consistent state:

  1. Remove Views\Account\_SetPasswordPartial.cshtml
  2. Remove Views\Account\_ChangePasswordPartial.cshtml
  3. Remove Views\Account\_RemoveAccountPartial.cshtml

All these have counterparts under the Manage controller. And finally:

  1. Remove the RemoveLogin() action method from ManageController. Make sure you only remove the GET method (lines 64 - 69), as the POST one is actually used. The list of logins is rendered by ManageLogins action.
网友答案:

Found out it's a known problem: http://blogs.msdn.com/b/webdev/archive/2014/08/04/announcing-new-web-features-in-visual-studio-2013-update-3-rtm.aspx

  1. When creating a default C# ASP.NET Web Application from MVC, WebAPI or SPA template with individual authentication, generated Views\Account\ _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml files contain invalid model.

In file _SetPasswordPartial.cshtml,

@model .Models.ManageUserViewModel Should be changed to: @model .Models.SetPasswordViewModel

In file _ChangePasswordPartial.cshtml,

@model Microsoft.AspNet.Identity.ManageUserViewModel Should be changed to: @model .Models.ChangePasswordViewModel

Similar problems exist for generated VB projects as well.

In file _SetPasswordPartial.vbhtml,

@ModelType ManageUserViewModel Should be changed to: @ModelType SetPasswordViewModel

In file _ChangePasswordPartial.vbhtml,

@ModelType ManageUserViewModel Should be changed to: @ModelType ChangePasswordViewModel

网友答案:

I confirmed issue also in VS2013 Ultimate Update#3. Submitted bug report to Microsoft Connect under Visual Studio and .NET Framework section.

分享给朋友:
您可能感兴趣的文章:
随机阅读: