RavenDb与ASP.NET MVC 3 - 如何使用身份证生成网址是什么? [英] RavenDb with ASP.NET MVC 3 - How to generate URL with ID?

查看:140
本文介绍了RavenDb与ASP.NET MVC 3 - 如何使用身份证生成网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的答案,但我是新来的RavenDb,所以我显然失去了一些东西。

This is probably a very simple answer, but i'm new to RavenDb, so i'm obviously missing something.

我得为ID的默认约定一个基本的对象:

I've got a basic object with the default convention for id:

public string Id { get; set; }

当我将它保存到文档存储,我看到它变得像一个值:

When i save it to the document store, i see it gets a value of like:

职位/ 123

这很好,但是...我怎么产生这样的网址:

Which is fine, but...how do i generate a URL like this:

www.mysite.com/edit/123

www.mysite.com/edit/123

如果我这样做:

@Html.ActionLink("Edit", "Posts", new { id = @Model.Id })

这将产生followiung网址:

It will generate the followiung URL:

www.mysite.com/edit/posts/123

www.mysite.com/edit/posts/123

这是不是我想要的。

当然,我没有做字符串操作?人们如何处理这个?

Surely i don't have to do string manipulation? How do people approach this?

推荐答案

RPM1984,
有几种方法可以对付的。

RPM1984, There are several ways you can deal with that.

1)您可以修改你的路由来处理这个问题:

1) You can modify your routing to handle this:

routes.MapRoute(
    "Default",                                                // Route name
    "{controller}/{action}/{*id}",                            // URL with parameters
    new { controller = "Home", action = "Index", id = "" });  // Parameter defaults

这将使MVC接受在他们斜线参数

This will allow MVC to accept parameters with slashes in them

2)你可以修改默认的ID生成策略:

2) You can modify the default id generation strategy:

 documentStore.Conventions.IdentityPartsSeparator = "-";

这将生成的ID:

帖子-1
帖子-2
等等

posts-1 posts-2 etc

请参阅也在这里:

<一个href=\"http://weblogs.asp.net/shijuvarghese/archive/2010/06/04/how-to-work-ravendb-id-with-asp-net-mvc-routes.aspx\">http://weblogs.asp.net/shijuvarghese/archive/2010/06/04/how-to-work-ravendb-id-with-asp-net-mvc-routes.aspx

这篇关于RavenDb与ASP.NET MVC 3 - 如何使用身份证生成网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆