1
我有实现MVC中5路由故障在调试预期的网址(如http://localhost/Download/Blog/1cf15fe6033a489a998556fedeab20a2/Test/1cd15fe6033a489a998556fedeab20a2
)导致下载控制器上的正确方法,然而,被称为did
和fid
总是null
。我究竟做错了什么?我也试图消除下载路线和具有以下属性定义控制器的路径:麻烦参数属性
[RoutePrefix("Download")] //on the controller
[Route("{action}/{did:guid}/Test/{fid:guid}")] //on the Blog Action
以下是我在我的RouteConfig.cs:
routes.MapRoute(
name: "Download",
url: "Download",
defaults: new { controller = "Download", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
这里是我的控制器:
[Route("{action}/{did}/Test/{fid}")]
public class DownloadController : Controller
{
public ActionResult Index()
{
return Redirect(HandleBadResponse(webResponse));
}
[Route("{action}/{did}/Test/{fid}")]//nope
public ActionResult Blog(HttpRequestMessage request,string did,string fid)
{
string server = Request.ServerVariables["SERVER_NAME"];
string pathStr = @"\\mypath\1cf15fe6033a489a998556fedeab20a2.xls";
byte[] fileBytes = System.IO.File.ReadAllBytes(pathStr);
string fileName = "test.txt";
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
您在实际控制器上的操作与操作方法相同。这是一个错字吗? – 2014-11-14 14:16:00
它不是一个错字,虽然我尝试了我在RouteConfig.cs文件中没有使用该路由列出的同样的事情,但都没有像我预期的那样工作,'fid'和'did'仍然是'null',但博客操作是呼吁下载控制器。 – Timigen 2014-11-14 14:18:44