有人可以帮我找出问题所在并且仍然向我解释控制器如何知道它应该使用哪个路由定义(因为在很多情况下,URI 可以适应多个路由定义)?
这是我的问题...
控制器方法:
[HttpGet]
public ActionResult PreencherFormulario(int idPacientePesquisa, int idFormularioPesquisa)
路线(所有在 Global.asax 上定义):
protected void Application_Start()
{
RouteTable.Routes.MapRoute(
"Busca",
"{controller}/{action}/{SearchString}/{SearchSubString}/{id}"
);
RouteTable.Routes.MapRoute(
"Participacao",
"{controller}/{action}/{id}"
);
RouteTable.Routes.MapRoute(
"ParticipacaoPesquisa",
"{controller}/{action}/{idPesquisa}/{nrProntuario}",
null,
new { idPesquisa = @"\d+" }
);
//!!! This should be the one used...
RouteTable.Routes.MapRoute(
name: "PreencherForm",
url: "{controller}/{action}/{idPacientePesquisa}/{idFormularioPesquisa}",
defaults: new { idPacientePesquisa = 1, idFormularioPesquisa = 1 },
constraints: new { idPacientePesquisa = @"\d+", idFormularioPesquisa = @"\d+" }
);
RouteTable.Routes.MapRoute(
"AdicionarRegraCID",
"{controller}/{action}/{a}/{b}/{c}",
new { controller = "Pesquisas", action = "AdicionarRegraCID", MetodoResultado = "", MetodoCancelar = "" }
);
网址:
http://localhost:61404/RealizacaoPesquisa/PreencherFormulario/1/1
错误:
The parameters dictionary contains a null entry for parameter 'idPacientePesquisa' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult PreencherFormulario(Int32, Int32)' in 'Prometheus.Controllers.RealizacaoPesquisaController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Nome do parâmetro: parameters