Errors caused by Individual User Accounts

M J 661 Reputation points
2021-06-18T18:08:08.247+00:00

I am using Visual Studio 2017.

When I set the project up I selected Individual User Accounts for the Authentication method. I have made no changes to that part of it. I added my models and some controllers and views and now when I try to build my code I get the following errors

Severity    Code    Description Project File    Line    Suppression State
Error   CS0234  The type or namespace name 'SelectListItem' does not exist in the namespace 'Greenbridge.Models.System.Web.Mvc' (are you missing an assembly reference?)    Greenbridge X:\DotNet Projects\Greenbridge\Greenbridge\Models\AccountViewModels.cs  21  Active


Error   CS0234  The type or namespace name 'SelectListItem' does not exist in the namespace 'Greenbridge.Models.System.Web.Mvc' (are you missing an assembly reference?)    Greenbridge X:\DotNet Projects\Greenbridge\Greenbridge\Models\ManageViewModels.cs   84  Active

Error   CS0266  Cannot implicitly convert type 'System.Collections.Generic.List<System.Web.Mvc.SelectListItem>' to 'System.Collections.Generic.ICollection<Greenbridge.Models.System.Web.Mvc.SelectListItem>'. An explicit conversion exists (are you missing a cast?)  Greenbridge X:\DotNet Projects\Greenbridge\Greenbridge\Controllers\AccountController.cs 297 Active

Without starting over from scratch how do I fix this?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. M J 661 Reputation points
    2021-06-28T21:29:21.493+00:00

    I tried explaining in the previosu posts that the code was created by Visual Studio. Evidently neither of the respondants have ever created an mvc project using Individual user accounts or they would have known that the code I was referencing was created by VISUAL STUDIO.

    Anyway I found the issue as I had found some other code online that was supposed to expand teh indivual user accounts code by creating roles. It was that class

    AuthorizeUserAccessLevel : AuthorizeAttribute
    

    that was causing this one to blow up. I removed that model and all was good with the world again.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Michael Taylor 49,166 Reputation points
    2021-06-18T18:44:23.693+00:00

    It looks like you created an MVC project. In ASP.NET there is the SelectListItem type that can be used for drop down lists. The problem, I would wager, though is that you are simply missing the using reference. In the editor you should be getting red squiggles under the type name reporting the same error message. Right click the identifier and Quick Actions should pop up. Within here one of the recommended code fixes will be something about adding Using System.Web.Mvc. This will add the using statement and fix the errors.

    The only thing I might be concerned about is that your project namespace contains System.Web.Mvc as well. Therefore it is possible you could run into namespace issues but that would depend upon your using statements. Use the Quick Action first and if that doesn't fix the issue then please post the line(s) reporting the error, the using statements you have and the namespace the code is contained in.


  2. Yijing Sun-MSFT 7,071 Reputation points
    2021-06-21T06:13:57.64+00:00

    Hi @M J ,
    As far as I think,the System.Web.MVC Assembly is not installed in the GAC. It has to be referenced from

    C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies  
    

    More details,you could refer to below article:
    https://stackoverflow.com/questions/2971588/can-i-use-system-web-mvc-from-a-class-library
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments