我有一个类似以下代码的操作:
public class EmployerController : Controller
{
public ActionResult Message(string contractorId, int projectId)
{....}
而一个 @html.ActionLink 作为
@Html.ActionLink("Message", "Message", "Employer", new { contractorId = @model.ContractorId, projectId = @model.ProjectId }, null)
我最终得到了像这样的URL:
http://localhost:3597/Employer/Message?contractorId=contractor&projectId=10
我希望我的url像这样
http://localhost:3597/Employer/Message/contractor/10
在我的RouteConfig.cs文件中,我已经添加了以下内容:
routes.MapRoute(
name: "MessageRoute",
url: "Employer/Message/{contractorId}/{projectId}",
defaults: new { controller = "Employer", action = "Message", contractorId = (string)null, projectId = 0 }
);
我缺少什么?如何在路由中禁用查询字符串?
感谢您的阅读。