以下是我在ASP.Net MVC应用程序的客户端/服务器模式(非嵌入式)中使用RavenDB所采取的步骤。虽然我完全按照步骤操作,但结果并不像预期的那样。如果有任何错误,请纠正我。
我有一个RestaurantModel.cs。
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,仍未插入数据。
我不知道我做错了什么,虽然我正在完全遵循我经历过的所有教程。如此多的尝试使用不同的方式,但仍无济于事。
提前感谢您的帮助!
尝试点击调试,它会打开localhost:33062,但它会显示我的服务器错误,如下所示。
我有一个RestaurantModel.cs
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; }
}
我有一个AdminController
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
答案 0 :(得分:1)
我真的不知道是什么原因导致了这个问题。只有一个问题,你刚刚编译了项目,或者你调用了你的行动domain: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
时,一切都按预期进行:
你能提供一些关于你想做的更多细节吗?