adding model based controller gives me an error in MVC 5

David Kamushadze 20 Reputation points
2024-06-10T10:18:57.1966667+00:00

I am trying to add model based controller, according to a tutorial:
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/accessing-your-models-data-from-a-controller

I tried reinstalling Visual studio, tried deleting project restarting tutorial I keep getting the error:

Microsoft Visual Studio


Error

There was an error running the selected code generator:

'Exception has been thrown by the target of an invocation.'


OK


User's image

User's image

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,393 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,554 questions
Entity Framework Core Training
Entity Framework Core Training
Entity Framework Core: A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.Training: Instruction to develop new skills.
3 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,276 Reputation points Microsoft Vendor
    2024-06-11T01:45:59.03+00:00

    Hi @David Kamushadze,

    Based on the information you provided, there is a problem.

    The connection string in web.config needs to be placed in the <connectionStrings> tag.

    User's image

    <connectionStrings>
    	<add name="MovieDBContext" connectionString="****" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful