问题描述
只是建立一个快速,简单的网站,MVC 3 RC2和RavenDB测试一些东西出来。
Just building a quick, simple site with MVC 3 RC2 and RavenDB to test some things out.
我已经能够做出一堆项目,但我很好奇,Html.ActionLink()如何处理乌鸦DB ID。
I've been able to make a bunch of projects, but I'm curious as to how Html.ActionLink() handles a raven DB ID.
我的例子:我有一个所谓的理由文档(某事的原因,只是文字居多),其中有原因的文字和链接列表。我可以通过我的存储库添加,删除,并做一切正常。
My example: I have a Document called "reasons" (a reason for something, just text mostly), which has reason text and a list of links. I can add, remove, and do everything else fine via my repository.
下面是列出一个项目符号列表中的每个原因,以作为第一个文本修改链接我的Razor视图的一部分:
Below is the part of my razor view that lists each reason in a bulleted list, with an Edit link as the first text:
@foreach(var Reason in ViewBag.ReasonsList)
{
<li>@Html.ActionLink("Edit", "Reasons", "Edit", new { id = Reason.Id }, null) @Reason.ReasonText</li>
<ul>
@foreach (var reasonlink in Reason.ReasonLinks)
{
<li><a href="@reasonlink.URL">@reasonlink.URL</a></li>
}
</ul>
}
问题
这工作得很好,除了编辑链接。而价值观和code出现在这里可以直接运行(即链接直接射击),RavenDB节省了我的文档的ID作为的理由/ 1。
This works fine, except for the edit link. While the values and code here appear to work directly (i.e the link is firing directly), RavenDB saves my document's ID as "reasons/1".
所以,当URL发生,并将其传递该ID,将所得的路线为http://本地主机:4976 /原因/编辑/理由/ 2。因此,ID正确地追加,但MVC是间preting它作为自己的路线。
So, when the URL happens and it passes the ID, the resulting route is "http://localhost:4976/Reasons/Edit/reasons/2". So, the ID is appended correctly, but MVC is interpreting it as its own route.
这是我怎么可能能够解决这个问题有什么建议?我需要创建一个特殊的途径来处理它还是有别的东西,我可以做什么?
Any suggestions on how I might be able to get around this? Do I need to create a special route to handle it or is there something else I can do?
推荐答案
我刚刚下载了最新版本的RavenDB并尝试了这一点。
I just downloaded the latest version of RavenDB and tried this out.
public class Entity {
public int Id { get;set; }
public string Text { get;set; }
}
当我将它保存到RavenDB,在乌鸦的ID是实体/ 1,但在RavenDB客户端映射能够成功地跨preT的Id从什么是在数据库中,我想整。
When I saved it to RavenDB, the id in Raven was "entities/1", but the mapping in RavenDB client was able to successfully interpret the Id from what was in the database to the integer that I wanted.
var entity = session.Load<Entity>(1);
Assert.IsTrue(entity.Id == 1);
您不需要扩展方法,这样一来,你就不需要改变任何路线如上所述,因为你将处理好醇'整数。字符串ID几乎是一个大忌,但令人惊讶这部作品让RavenDB是回到了狩猎。
You do not need a extension method, and this way you would not need to alter any routes as mentioned above, because you will be dealing with good ol' integers. The string Ids were almost a deal breaker, but amazingly this works so RavenDB is back in the hunt.
- 注:我从看罗布阿什顿谈话,意识到他所有的文档类有整数作为IDS想通了这一点。
这篇关于RavenDB IDS和ASP.NET MVC3路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!