您可以通过替换斜杠来解决此问题。
ActionLink(item.InterfaceName.Replace('/', '-'), ....)
在此之后,您的链接将如下所示:localhost:1842/Interface/Name/FastEthernet0-0
。 当然,你在你的控制器ActionMethod会表现不好,因为它会期待一个良好命名的接口,因此在调用该方法,你需要恢复的更换:
public ActionResult Name(string interfaceName)
{
string _interfaceName = interfaceName.Replace('-','/');
//retrieve information
var result = db.Interfaces...
}
另一种方法是建立一个自定义路线追赶您的要求:
routes.MapRoute(
"interface",
"interface/{*id}",
new { controller = "Interface", action = "Name", id = UrlParameter.Optional }
);
Your method would be:
public ActionResult Name(string interfaceName)
{
//interfaceName is FastEthernet0/0
}
该解决方案建议由达林季米特洛夫here
如果您编码一个斜线,并将其打印为斜杠,它仍然会破坏路线。在我小小的世界里,我使用cisco设备的地方,OP的命名约定是唯一有效的。可能与供应商有所不同,但我从未见过不同的命名方案。 – Marco