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,503 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,999 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 29,746 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.