我因此定义了两条路线:
//Custom route for legacy admin page
routes.MapPageRoute(
"LocaliseRoute", // Route name
"Admin/Localise", // URL
"~/Views/Admin/Localise.aspx" // File
);
routes.MapRoute(
"Admin", // Route name
"Admin/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
以下两个 GET 都可以正常工作:
http://pegfect.local/Admin/PegModelUpload
http://pegfect.local/Admin/Localise
但是,前者的形式动作是/Admin/Localise?action=UploadPegModel&controller=Admin
导致“WTF?!”的表达
表格的代码是:
@using (Html.BeginForm("UploadPegModel", "Admin", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return validateForm();" }))
{
<input type='file' name='file' id='file' />
<input type="submit" value="submit" />
}