none
Asp.Net core 2.0 Mvc app error RRS feed

  • Question

  • Have an Asp.net core 1.1 Mvc app that I converted to 2.0 that includes a custom Templates/ folder.  When I attempt to add a controller w EF actions, I get the following error:

    VS 2017 update 3 new controller error

    I assume there are updated templates for core 2.0 but don't know where to find them??
    Friday, September 8, 2017 9:47 PM

All replies

  • Hi Alex,

    Welcome to the MSDN forum.

    Refer to the error message, please check this similar issue: Migration 1.1 to 2.0 : Scaffold multiple problems and try the following solution that provided by NicolasREY:

    I checked the differences, and here are the mandatory modifications:

    Templates\ControllerGenerator\MvcControllerWithContext.cshtml

    Add:

    @using System.Collections.Generic;
    @using System.Linq;

    in addition of:

    using System.Collections.Generic;
    using System.Linq;

    So the 'header' looks like :

    @inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
    @using System.Collections.Generic;
    @using System.Linq;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Rendering;
    using Microsoft.EntityFrameworkCore;

    Templates\ViewGenerator\List.cshtml

    Add :

    @using System.Collections.Generic;
    @using System.Linq;

    so the 'header' looks like :

    @inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
    @using Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
    @using System.Collections.Generic
    @using System.Linq
    @@model @GetEnumerableTypeExpression(Model.ViewDataTypeName)

    Then make the following replacement :

    IEnumerable<PropertyMetadata> var properties = Model.ModelMetadata.Properties;

    I didn't have to change anything else to my other view templates, and I don't use other controller templates.

    If the above not works, please redirect to this appropriate forum: https://forums.asp.net/1255.aspx/1?ASP+NET+Core and start a new thread to seek for a more professional support, since our forum is to discuss the VS IDE, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, September 11, 2017 6:18 AM