![](/img/trans.png)
[英]c# f#: WebApi: How do I do the equivalent of RouteCollection.RouteExistingFiles with HttpRouteCollection?
[英]how do you make a controller in F# that uses hyphens?
我有一個.net MVC網站,我的控制器是用f#編寫的。 但我無法找到如何在我的控制器中使用連字符。
我想要的東西:
domain.com/some-cool-page
這是如何在F#中完成的?
這是我的聯系人控制器的一個例子:
type ContactController() =
inherit Controller()
member x.Index () =
let version = typeof<int * int>.Assembly.GetName().Version
let msg = sprintf "This web page is running using F# version %s." (version.ToString(4))
x.ViewData.["Message"] <- msg
let uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri)
let param1 = HttpUtility.ParseQueryString(uri.Query).Get("id")
x.ViewData.["idinfo"] <- param1
x.View("~/Views/contact.cshtml")
以下是使用路由配置執行此操作的一種方法:
routes.MapRoute(
"CoolPage",
"some-cool-page/{action}/{id}",
{ controller = "Contact"; action = "Index"; id = UrlParameter.Optional }
) |> ignore
在“默認”路由之前添加它,您可以通過/some-cool-page
訪問ContactsController和相應的視圖。
您通常會在global.asax.fs文件中找到路由配置,具體取決於您使用的模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.