Dinesh Kudale

Dinesh Kudale

  • 1.5k
  • 127
  • 16.8k

"The system cannot find the file specified." in asp.Net MVC

Jul 6 2018 4:34 AM
I have created asp.Net MVC application (code first approach). If I run Index.cshtml file, then it arises following error message in the browser.
"The system cannot find the file specified"
Error Shows in this line
Line 26: db.Standards.Add(standard1);
If it runs successfully, then it must create Database in App_Data folder. But this Index.cshtml is not running successfully. Please guide that how to resolve this problem.
In Visual Stusdio 2015->File->New->Project->Asp.Net Web Application, Name of Project:Note7Page55->Seelect MVC option->ok.
 
Model Folder->Student.cs
  1. namespace Note7Page55.Models  
  2. {  
  3.     public class Student  
  4.     {  
  5.         public int StudentId { getset; }  
  6.         public string StudentName { getset; }  
  7.         public string Address { getset; }  
  8.         public string City { getset; }  
  9.         public Standard Standard { getset; }  
  10.     }  
  11. }  
Model Folder->Standard.cs
  1. using System.Collections.Generic;  
  2. namespace Note7Page55.Models  
  3. {  
  4.     public class Standard  
  5.     {  
  6.         public int StandardId { getset; }  
  7.         public string StandardName { getset; }  
  8.         public ICollection<Student> Students { getset; }  
  9.     }  
  10. }  
Model Folder->SchoolContext.cs
  1. using System.Data.Entity;  
  2. namespace Note7Page55.Models  
  3. {  
  4.     public class SchoolContext : DbContext    
  5.     {  
  6.         public SchoolContext() : base(){}          
  7.         public DbSet<Standard> Standards { getset; }  
  8.         public DbSet<Student> Students { getset; }  
  9.     }  
  10. }  
Controller Folder-> SchoolController.cs
  1. using System.Web.Mvc;  
  2. using Note7Page55.Models;  
  3. namespace Note7Page55.Controllers  
  4. {  
  5.     public class SchoolController : Controller  
  6.     {  
  7.         SchoolContext db = new SchoolContext();  
  8.         // GET: School  
  9.         public ActionResult Index()  
  10.         {  
  11.             Standard standard1 = new Standard()  
  12.             {  
  13.                 StandardName = "Std. 5th"  
  14.             };  
  15.             Student student1 = new Student()  
  16.             {  
  17.                 StudentName = "Dinesh Kudale",  
  18.                 Address = "Gar Fata",  
  19.                 City = "Patas"  
  20.             };  
  21.             db.Standards.Add(standard1);  
  22.             db.Students.Add(student1);  
  23.             db.SaveChanges();  
  24.             return View();             
  25.         }  
  26.     }  
  27. }  
Added View as Index.cshtml
  1. @model Note7Page55.Models.Student  
  2.   
  3. @{  
  4.     ViewBag.Title = "Index";  
  5. }  
  6. <h2>Index</h2>
 When I run Index.cshtml file, then it arises following error message in the browser.
"The system cannot find the file specified"
Please guide that how to resolve this problem.

Answers (4)