Asp.net mvc MVC中的RavenDB未将数据保存到数据库中

Asp.net mvc MVC中的RavenDB未将数据保存到数据库中,asp.net-mvc,ravendb,Asp.net Mvc,Ravendb,下面是我在ASP.NETMVC应用程序中以客户机/服务器模式(非嵌入式)使用RavenDB的步骤。虽然我完全按照步骤进行,但结果并不像预期的那样。如果有什么错误,请纠正我 通过Nuget安装RavenDB.Client和RavenDB.Server 转到Packages文件夹,启动Raven.Server.exe以运行服务 在浏览器中打开,RavenStudio启动 创建了一个名为“testdb”的数据库 我有一个餐厅模型 internal class RestaurantModel{ pu

下面是我在ASP.NETMVC应用程序中以客户机/服务器模式(非嵌入式)使用RavenDB的步骤。虽然我完全按照步骤进行,但结果并不像预期的那样。如果有什么错误,请纠正我

  • 通过Nuget安装RavenDB.Client和RavenDB.Server
  • 转到Packages文件夹,启动Raven.Server.exe以运行服务
  • 在浏览器中打开,RavenStudio启动
  • 创建了一个名为“testdb”的数据库
  • 我有一个餐厅模型

    internal class RestaurantModel{
      public string ResName { get; set; }
      public string ResAddress { get; set; }
      public string ResCity { get; set; }
      public string ResState { get; set; }
      public int ResPostcode { get; set; }
      public string ResPhoneNum { get; set; }
    }
    
  • 在我的控制器中,我初始化了文档存储,并打开了会话

    public ActionResult Index()
    {
        using (var store = new DocumentStore
        {
            Url = "http://localhost:8080/",
            DefaultDatabase = "testdb"
        })
        {
            store.Initialize();
    
            using (var session = store.OpenSession())
            {
                session.Store(new RestaurantModel
                {
                    ResName = "TestName",
                    ResAddress = "Test Address",
                    ResCity = "TestCity",
                    ResState = "TestState",
                    ResPostcode = 82910,
                    ResPhoneNum = "02-28937481"
                });
    
                session.SaveChanges();
    
            }
        }
    
            return View();
    }
    
  • 构建解决方案。刷新localhost:8080,数据仍未插入

  • 我不知道我做错了什么,虽然我完全按照我所经历的所有教程。用不同的方法做了这么多尝试,但仍然无济于事

  • 提前感谢您的帮助

    尝试点击debug,它会打开localhost:33062,但随后会显示服务器错误,如下所示

    #更具体地说#
  • 我有一个餐厅模型

    internal class RestaurantModel
    {
      public string ResName { get; set; }
      public string ResAddress { get; set; }
      public string ResCity { get; set; }
      public string ResState { get; set; }
      public int ResPostcode { get; set; }
      public string ResPhoneNum { get; set; }
    }
    
  • 我有一个管理员控制器

    using FYP2.Models;
    using Raven.Client.Document;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace FYP2.Controllers
    {
    public class AdminController : Controller
    {
        // GET: Admin
        public ActionResult Index()
        {
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080/",
                DefaultDatabase = "foodfurydb"
            })
            {
                store.Initialize();
    
                using (var session = store.OpenSession())
                {
                    session.Store(new RestaurantModel
                    {
                        ResName = "Boxer Republic",
                        ResAddress = "NO 2A-G, Jalan BK 5A/2C",
                        ResCity = "Puchong",
                        ResState = "Selangor",
                        ResPostcode = 47180,
                        ResPhoneNum = "03-80748088"
                    });
    
                    session.SaveChanges();
    
                }
            }
    
                return View();
        }
    
        public ActionResult AdminLogin()
        {
            return View();
        }
    
        public ActionResult AddRestaurant()
        {
            return View();
        }
    
        public ActionResult ManageFoodMenu()
        {
            return View();
        }
    
        public ActionResult ManageOrder()
        {
            return View();
        }
    
        public ActionResult ManageReservation()
        {
            return View();
        }
    
    }
    }
    
  • 我有管理员视图,包括


  • AddRestaurant、AdminLogin、ManageFoodMenu、ManageOrder、ManageReservation我真的不知道是什么导致了这个问题。只有一个问题,您刚刚编译了项目,还是调用了您的操作
    域:port/yourcontroller/index

    我创建了一个mvc项目并复制了您的代码:

    public class HomeController : Controller
    {
        internal class RestaurantModel
        {
            public string ResName { get; set; }
            public string ResAddress { get; set; }
            public string ResCity { get; set; }
            public string ResState { get; set; }
            public int ResPostcode { get; set; }
            public string ResPhoneNum { get; set; }
        }
    
        public ActionResult Index()
        {
            using (var store = new DocumentStore
            {
                Url = "http://locaslhost:8080/",
                DefaultDatabase = "testdb"
            })
            {
                store.Initialize();
    
                using (var session = store.OpenSession())
                {
                    session.Store(new RestaurantModel
                    {
                        ResName = "TestName",
                        ResAddress = "Test Address",
                        ResCity = "TestCity",
                        ResState = "TestState",
                        ResPostcode = 82910,
                        ResPhoneNum = "02-28937481"
                    });
    
                    session.SaveChanges();
    
                }
            }
    
            return View();
        }
    }
    
    当我访问路径
    http://localhost:50791/
    对应于我的
    HomeController/Index
    ,一切如期进行:


    你能提供你正在尝试做的更多细节吗?

    方法
    public ActionResult Index(){}
    是来自
    控制器的
    操作
    ,对吗?这意味着您的项目将响应该路线。试试这个:点击项目上的调试。它将启动您的mvc应用程序。然后,如果您不在HomeController中,请添加/NameOfYouControllerWithoutController。它将创建您的数据库并添加数据!我试过调试。然后打开localhost:33062,但显示服务器错误。我想知道怎么了?你创建了什么类型的项目?ASP.NET MVC。我在上面的项目中添加了额外的信息。不管怎么说,我也尝试使用MVC创建一个新的、干净的项目,这次成功了!我不知道出了什么问题。
    public class HomeController : Controller
    {
        internal class RestaurantModel
        {
            public string ResName { get; set; }
            public string ResAddress { get; set; }
            public string ResCity { get; set; }
            public string ResState { get; set; }
            public int ResPostcode { get; set; }
            public string ResPhoneNum { get; set; }
        }
    
        public ActionResult Index()
        {
            using (var store = new DocumentStore
            {
                Url = "http://locaslhost:8080/",
                DefaultDatabase = "testdb"
            })
            {
                store.Initialize();
    
                using (var session = store.OpenSession())
                {
                    session.Store(new RestaurantModel
                    {
                        ResName = "TestName",
                        ResAddress = "Test Address",
                        ResCity = "TestCity",
                        ResState = "TestState",
                        ResPostcode = 82910,
                        ResPhoneNum = "02-28937481"
                    });
    
                    session.SaveChanges();
    
                }
            }
    
            return View();
        }
    }