我在asp.net项目中定义了一条新路线
routes.MapRoute(
name: "Default",
url: "{controller}.{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
和控制器(让我们称之为TempController)有两个动作:
如何创建到TempController的路由以执行CheckParameter?
感谢您的每一个答案!
答案 0 :(得分:1)
Temp的主要路线:
routes.MapRoute(
name: "TempHome",
url: "{controller}.{action}",
defaults: new { controller = "Temp", action = "Index"}
);
检查临时路线:
routes.MapRoute(
name: "TempCheck",
url: "{controller}.{action}/{id}",
defaults: new { controller = "Temp", action = "CheckParameter", id = UrlParameter.Optional }
);
用法:http://www.website.com/temp.checkparameter/id
或者你可以这样:
routes.MapRoute(
name: "TempCheck",
url: "CheckSomething/{id}",
defaults: new { controller = "Temp", action = "CheckParameter", id = UrlParameter.Optional }
);
id = 10的用法: http://www.website.com/CheckSomething/10
答案 1 :(得分:0)
新路线
public ActionResult CheckParameter(string stringParam){
}
TempController.cs
localhost:9090/temp/CheckParameter/PassAnyString
调用
http://localhost:9090/temp/CheckParameter?stringParam=11
In a @Url.Action would be :
@Url.Action("CheckParameter","temp", new {stringParam=11});
如果您不想添加新路线,也可以尝试此
function getGeneralTimeFormat()
{
return 'Y-m-d H:i:s';
}