Add namespace to all views in ASP.NET MVC 6

后端 未结 3 1137
悲哀的现实
悲哀的现实 2021-02-18 13:56

I’m using MVC 6 and would like to be able to access a particular namespace globally from all of my Razor views. In MVC 5 this was fairly simple; I’d just add the following code

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-18 14:17

    Add your namespaces to the_ViewImports.cshtml file (it's under the Views folder).

    Example file:

    @using Microsoft.AspNetCore.Identity
    @using Jifiti.Registry.Web.Models.AccountViewModels
    @using Jifiti.Registry.Web.Models.ManageViewModels
    
    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    

提交回复
热议问题