如果我有像这样的路由器:
app.UseMvc(config => {
config.MapRoute(
name: "route",
template: "{controller}/{action}/{id?}"
);
});
是否可以调用参数名为id
以外的方法,并且仍然可以绑定URL中的值。
public void SetHeight(int height){
//height do not binds value from URL to height
}
public void SetWidth(int width){
//height do not binds value from URL to width
}
public void SetHeight(int id){
//works as expected however I would like to have different
//parameters name for different action on controller
}
public void SetWidth(int id){
//works as expected however I would like to have different
//parameters name for different action on controller
}
是否有一些注释或类似的东西可以启用不同的参数名称? 类似的东西:
public void SetHeight([FromUrl(name = "id")]int height){
...
}
答案 0 :(得分:2)
你可以试试这个:
[Route("[controller]/[action]/{height}")]
public void SetHeight(int height)
{
//height do not binds value from URL to height
}
[Route("[controller]/[action]/{width}")]
public void SetWidth(int width)
{
//height do not binds value from URL to width
}