I have a .net MVC website and my controllers are written in f#. But I'm having trouble finding out how to use hyphens in my controllers.
I want something like:
domain.com/some-cool-page
How is this done in F#?
Here's an example of my contact controller:
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")
Here's one way to do it with routing configuration:
routes.MapRoute(
"CoolPage",
"some-cool-page/{action}/{id}",
{ controller = "Contact"; action = "Index"; id = UrlParameter.Optional }
) |> ignore
Add this before the "Default" route, and you can access the ContactsController and the appropriate view via /some-cool-page
.
You'll typically find the routing configuration in your global.asax.fs file, depending on the template you're using.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.