如何使用特定的 url asp mvc 进行操作
how to get action with specific url asp mvc
我想获取特定的 link 以接收操作
这是我的控制器:
namespace tabi.Controllers
{
public class CategoryController : Controller
{
public ActionResult List(string name=null)
{
ViewBag.name = name;
return View();
}
}
}
如何使用此 link 采取行动:
/category/game
游戏是名称参数值
并且不要更改默认路由
如果你还没有定义自定义路由,你必须使用下面的url:
/Category/List?name=game
如果您指定自定义路由以允许 List 作为默认操作,并且 /{name}
到该路由(而不是 ID),它将使用您指定的路由,例如:
routes.MapRoute(
name: "game",
url: "{controller}/{name}",
defaults: new { controller = "Home", action = "List" });
这条路线应该支持URL。
我想获取特定的 link 以接收操作
这是我的控制器:
namespace tabi.Controllers
{
public class CategoryController : Controller
{
public ActionResult List(string name=null)
{
ViewBag.name = name;
return View();
}
}
}
如何使用此 link 采取行动:
/category/game
游戏是名称参数值
并且不要更改默认路由
如果你还没有定义自定义路由,你必须使用下面的url:
/Category/List?name=game
如果您指定自定义路由以允许 List 作为默认操作,并且 /{name}
到该路由(而不是 ID),它将使用您指定的路由,例如:
routes.MapRoute(
name: "game",
url: "{controller}/{name}",
defaults: new { controller = "Home", action = "List" });
这条路线应该支持URL。