none
"The system cannot find the file specified." in asp.Net MVC application (code first approach)...

    Pertanyaan

  • 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

    namespace Note7Page55.Models
    {
        public class Student
        {
            public int StudentId { get; set; }
            public string StudentName { get; set; }
            public string Address { get; set; }
            public string City { get; set; }
            public Standard Standard { get; set; }
        }
    }

    Model Folder->Standard.cs

    using System.Collections.Generic;
    namespace Note7Page55.Models
    {
        public class Standard
        {
            public int StandardId { get; set; }
            public string StandardName { get; set; }
            public ICollection<Student> Students { get; set; }
        }
    }

    Model Folder->SchoolContext.cs

    using System.Data.Entity;
    namespace Note7Page55.Models
    {
        public class SchoolContext : DbContext  
        {
            public SchoolContext() : base(){}        
            public DbSet<Standard> Standards { get; set; }
            public DbSet<Student> Students { get; set; }
        }
    }

    Controller Folder-> SchoolController.cs

    using System.Web.Mvc;
    using Note7Page55.Models;
    namespace Note7Page55.Controllers
    {
        public class SchoolController : Controller
        {
            SchoolContext db = new SchoolContext();
            // GET: School
            public ActionResult Index()
            {
                Standard standard1 = new Standard()
                {
                    StandardName = "Std. 5th"
                };
                Student student1 = new Student()
                {
                    StudentName = "Dinesh Kudale",
                    Address = "Gar Fata",
                    City = "Patas"
                };
                db.Standards.Add(standard1);
                db.Students.Add(student1);
                db.SaveChanges();
                return View();           
            }
        }
    }

    Added View as Index.cshtml

    @model Note7Page55.Models.Student
    
    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>

    When I run Index.cshtml file, then it arises following error message in browser. 
    "The system cannot find the file specified"
    Please guide that how to resolve this problem.

    • Dipindahkan oleh CoolDadTxMVP Jumat, 06 Juli 2018 13.53 ASP.NET related
    Jumat, 06 Juli 2018 07.51

Semua Balasan