Last post Sep 26, 2016 07:52 PM by Mark Lindahl
Sep 26, 2016 04:56 PM|Mark Lindahl|LINK
I'm trying to create a VS2015 solution which includes project that just contains the model classes. This model class project is referenced by both an ASP.Net Core web application and an API project in the same solution. In the _LoginPartial.cshtml view
of the web application, I am getting 'Type or namespace name ApplicationUser could not be found'. ApplicationUser is defined in ApplicationDBContext.cs in my model class project and I am referencing that namespace (@using SP_Common_Classes.Models.DB) in the
view (and the namespace in ApplicationDBContext is SP_Common_Classes.Models.DB). The API also doesn't return anything, but I haven't looked into that further and am trying to figure out the web application.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public class ApplicationUser : IdentityUser
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
Any suggestions as to what else I need to look for?
Sep 26, 2016 05:09 PM|Dmitry Sikorsky|LINK
You have to specify whole type name (including namespace) in you view's @model:
Or you can use _ViewImports.cshtml to import namespaces for you views:
Actually why you put your ApplicationUser class definition inside the
ApplicationDbContext class definition?
Sep 26, 2016 05:28 PM|Mark Lindahl|LINK
1). Tried @model SP_Common_Classes.Models.DB.ApplicationDbContext.ApplicationUser, but get a complaint that that is not a namespace (the name space is SP_Common_Classes.Models.DB).
2). Already tried @using SP_Common_Classes.Models.DB as mentioned in my original post and it doesn't work.
As to having ApplicationUser defined in ApplicationDBContext, that was just the default way VS2015 created it for me and I just moved everything in models (including the DBContext file) to my model class project en masse. I'm open to other ways of doing
Sep 26, 2016 05:37 PM|Dmitry Sikorsky|LINK
Try to move ApplicationUser out from the
ApplicationDbContext class. Just put it into the namespace. It is not possible that it doesn't work :) It must work. Could you try to reference that class from the controller? If you can do that views must work too. If you can't - you have wrong dependency
in the project.json.
Sep 26, 2016 07:52 PM|Mark Lindahl|LINK
My Using was incorrect. I looked in a Controller in my web application and it referenced SP_Common_Classes.Models, not SP_Common_Classes.Models.DB (even though the class I wanted is in the DB directory) and it worked. Not sure why, but it worked. Thanks
for "forcing" me to look at my code more closely.