Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The Problem is that my model and context class don't show in options the computer says no model class

Template

MVC controller with read/write actions and views, using Entity Framework

Model class

No Model classes are available

Data context Class do not have any option


EmpModel.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FileUploadDownLoadInMVC.Models
{
public class EmpModel
{
public HttpPostedFileBase files { get; set; }
}

public class FileDetailsModel
{
public int Id { get; set; }
public String FileName { get; set; }
public byte[] FileContent { get; set; }

public virtual ICollection<empmodel> File { get; set; }
}
}

dbcon.cs

using System;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FileUploadDownLoadInMVC.Models
{
public class dbcon : DbContext
{
public dbcon() : base("dbcon")
{
}

public DbSet<empmodel> File { get; set; }
public DbSet<filedetailsmodel> Details { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// modelBuilder.Conventions.Remove<pluralizingtablenameconvention>();
}
}
}



web.config

<connectionStrings>
    <add name="dbcon"  
         connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\university.mdf;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>


What I have tried:

i have made my model class and DBContext class and web.conf but i want to make controller and view for the following model using my model and DBcontext class they dont show in model when i add controller .
Posted
Updated 28-Dec-17 13:47pm

1 solution

Im not really quite sure why you don't just create the controller, associated view...have have the View be tightly bound to the desired model class, in this case your EmpModel class.

If trying to create a template isn't working, just create a new controller called EmployeeController. Then create a new view called Employee by clicking on your views folder and doing right click, add new item (or whatever the option is). Then within your view you would declare the model for the view to be something like @model FileUploadDownloadInMVC.Models.EmpModel.

Then for your controller, it would look something like this

C#
public class EmployeeController : Controller
{

    //passing in ID here as im assuming you've got some sort of unique ID to show records
    public ActionResult Employee(string id)
    {
       var model = new EmpModel();

       return View(model);
    }
}


I think you are stuck on trying to use the built in templating of visual studio. It is probably just as quick to build the model/view/controllers you need manually (maybe not just as quick but whats another 10 seconds).

Given this is pretty basic stuff, I recommend you use google or the following links for more information.

asp.net MVC tutorial - Google Search[^]

ASP.NET MVC Guidance | The ASP.NET Site[^]

Getting Started with Entity Framework 6 Code First using MVC 5 | Microsoft Docs[^]

Getting Started with ASP.NET MVC 5 | Microsoft Docs[^]

Step-by-step ASP.NET MVC Tutorial for Beginners - YouTube[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900