我正在寻找有关使用C#在MVC中路由的一些信息.我目前非常了解MVC中的路由基础,但我正在寻找的东西有点难以找到.
实际上,我想要找到的是一种定义采用单个参数的单一路径的方法.
我在网上找到的常见例子都是基于这个例子
routes.MapRoute(
"Default",
"{controller}.mvc/{action}/{id}"
new { controller = "Default", action="Index", id=""});
Run Code Online (Sandbox Code Playgroud)
通过映射此路由,您可以映射到任何控制器中的任何操作,但是如果要将任何内容传递给操作,则必须将方法参数称为"id".如果可能的话,我想找到解决这个问题的方法,这样我就不必经常指定路由只是为了在我的动作中使用不同的参数名称.
有没有人有任何想法,或找到解决方法?
关于我如何将其重构为一个体面的模式,我正在努力解决一个小问题.
public class DocumentLibrary
{
private IFileSystem fileSystem;
private IDocumentLibraryUser user;
public DocumentLibrary(IDocumentLibraryUser user) : this(user, FileSystemFrom(user)) { }
public DocumentLibrary(IDocumentLibraryUser user, IFileSystem fileSystem)
{
this.user = user;
this.fileSystem = fileSystem;
}
public void Create(IWorkerDocument document)
{
document.SaveTo(fileSystem);
}
public IWorkerDocument AttemptContractRetrieval()
{
return new Contract(fileSystem, user);
}
public IWorkerDocument AttemptAssignmentRetrieval()
{
return new Assignment(fileSystem, user);
}
private static IFileSystem FileSystemFrom(IDocumentLibraryUser user)
{
var userLibraryDirectory = new DirectoryInfo("/DocLib/" + EnvironmentName() + "/" + user.Id);
return new FileSystem(userLibraryDirectory);
}
private static …Run Code Online (Sandbox Code Playgroud)