gpt4 book ai didi

c# - ASP.NET MVC 路由 '/category/{string}' 而不是 '/category/details/{string}'

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:47 24 4
gpt4 key购买 nike

我想创建一个路径来访问我的类别,如下所示:/category/{id} 而不是 /category/details/{id}

我试过很多这样的例子

routes.MapRoute(
"Category",
"category/{id}",
new { controller = "category", action = "details", id = UrlParameter.Optional },
new string[] { "Project.Controllers" }
);

但是好像不行。有人可以帮我解决这个问题吗?

这是我的 Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Project.Controllers
{
public class CategoryController : Controller
{
public ActionResult Details(string id)
{
return Content(id);
}
}
}

最佳答案

我做的一切都正确,我只是把它放在我的默认路线下面,需要把新的路线放在默认路线上。

关于c# - ASP.NET MVC 路由 '/category/{string}' 而不是 '/category/details/{string}',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12497108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com