"The woods". Read action in MVC "There is no constructor without parameters for this object."

I am working on a basic MVC5 / EF6 application, and I run the following error when I try to raise the Read action in MVC:

Error 

There was an error running the selected code generator: 
'No Parameterless constructor defined for this object'

In any case, this is not necessary, because I am reading, not deleting or updating, but in the model in question there is no constructor without parameters (as for the models below).

public class Article
{
    public int ArticleID { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public DateTime PublishDate { get; set; }

    public virtual Author Author { get; set; }

    public Article()
    {
    }
}

My controller is below, and it also has a parameterless constructor:

public ArticleController()
{
    connection = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    context = new TRNContext(connection);
}

// GET: Article
public ActionResult Index(int id)
{
    return View(context.Articles.SingleOrDefault(a => a.ArticleID == id));
}
+7
source share
4 answers

The error message was slightly misleading. Less constructor with a parameter is required, but this is not the model for which it is needed.

+8
source

ASP.NET Core MVC - . , dbContext, , . . , .

  1. Startup.cs - . enter image description here

  2. Appsetting.json - . enter image description here

+6

. , DbContext. , . , .

0

aspnet, Program IWebHostBuilder, dbcontext .

, mvc- aspnet core 2.2.

, , . Program , dbcontext . https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dbcontext-creation

0

Source: https://habr.com/ru/post/1584452/


All Articles