繁体   English   中英

如何在MVC中的url中显示参数的值

[英]How to show parameter's value in url in MVC

我是这个mvc路由的新手。 我有默认生成的网址是:

HTTP://本地主机:6236 / ProductCategories名=教育%20Trainers

但我希望我的网址只显示为:

HTTP://本地主机:6236 / Educational_Trainers

如何做到这一点,请指导我。 我有下面的控制器

Async Function Index(name As String) As Task(Of ActionResult)
        If String.IsNullOrEmpty(name) Then
            'Dim productCategories1 = db.ProductCategories.Include(Function(x) x.ProductSubcategories)
            'Return View(Await productCategories1.ToListAsync())
            Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
        End If
        Dim productCategories = db.ProductCategories.Where(Function(x) x.Title.TitleText = name) '.Include(Function(p) p.Title).Include(Function(x) x.ProductSubcategories)
        Dim title As Title = db.Titles.Where(Function(x) x.TitleText = name).FirstOrDefault
        TempData("cat") = title.TitleText
        TempData("details") = title.Description
        Return View(Await productCategories.ToListAsync())
    End Function

好的,我在路由配置文件中做了一些工作,并且有点接近我的解决方案。 我将以下代码添加到我的route.config文件中

routes.MapRoute(
    name:="ProductCategories",
    url:="{name}",
    defaults:=New With {.controller = "ProductCategories", .action = "Index", .name = UrlParameter.Optional}
    )

我得到我的网址如下

HTTP://本地主机:6236 /教育%20Trainers

但现在我想从此网址中删除%20 ...任何帮助将不胜感激。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM