我有以下Html:
<%: Html.ActionLink(item.ProductName, "Details", "Product", new { item.ProductId }, null)%>
Run Code Online (Sandbox Code Playgroud)
这被呈现为:
<a href="/Product/Details?ProductId=1">My Product Name</a>
Run Code Online (Sandbox Code Playgroud)
但是,当我点击这个时,我收到以下错误:
参数字典包含非可空类型'System.Int32'的参数'id'的空条目,用于'MyProject.Controllers.ProductController'中的方法'System.Web.Mvc.ActionResult Details(Int32)'.可选参数必须是引用类型,可空类型,或者声明为可选参数.
参数名称:参数
我的路由似乎不喜欢"?ProductId = 1"查询字符串.
如果我改用:
<%: Html.ActionLink(item.ProductName, string.Format("Details/{0}", item.ProductId), "Product", null, null)%>
Run Code Online (Sandbox Code Playgroud)
我得到以下链接呈现:
<a href="/Product/Details/1">My Product Name</a>
Run Code Online (Sandbox Code Playgroud)
...单击时这可以正常工作.
我错过了一些基本的东西吗?我想使用RouteValues,但我不明白为什么会抛出这个错误.如何让Controller方法接受查询字符串参数?
我唯一的路线映射是:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud) model-view-controller asp.net-mvc asp.net-mvc-routing asp.net-mvc-3
在EmbeddableDocumentStore类上调用Initialize时,我遇到了一个非常令人沮丧的错误.这是一个尝试在c:\ temp\ravenDb启动或初始化RavenDB数据库的WPF应用程序.
我的代码是:
EmbeddableDocumentStore _documentStore = new EmbeddableDocumentStore()
{
DataDirectory = @"C:\temp\RavenDb"
};
using (_documentStore.Initialize())
{
}
Run Code Online (Sandbox Code Playgroud)
相当简单.在调用Initialize()时发生错误.这是完整的错误:
Microsoft.Isam.Esent.Interop.EsentFileNotFoundException occurred
Message=File not found
Source=Esent.Interop
StackTrace:
at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:line 2736
InnerException:
Run Code Online (Sandbox Code Playgroud)
令人沮丧的是,当我创建一个新的WPF应用程序并使用相同的代码进行复制时,它可以正常工作,并且能够初始化和创建基本文件.然后,当我回到我的主WPF应用程序时 - 数据库现在能够初始化(因为文件已经创建),但任何Session.Query调用都会导致以下错误:
System.IO.FileNotFoundException occurred
Message=segments.gen
Source=Lucene.Net
StackTrace:
at Lucene.Net.Store.RAMDirectory.OpenInput(String name) in z:\Libs\lucene.net\src\core\Store\RAMDirectory.cs:line 301
InnerException:
Run Code Online (Sandbox Code Playgroud)
编辑:完整代码:从后台工作者委托中调用:
private void RefreshGrid()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync(_domainType);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
e.Result …Run Code Online (Sandbox Code Playgroud)