Url.Action map a wrong link from Route attribute

前端 未结 3 1981
情歌与酒
情歌与酒 2021-01-18 00:15

This is target controller and action:

[RoutePrefix(\"Editor\")]
public class EditorController : Controller

[HttpGet]
    [Route(\"{id:int}\")]
    public A         


        
3条回答
  •  借酒劲吻你
    2021-01-18 00:31

    To achieve the result you want you have to use a route name:

    [HttpGet]
    [Route("{id:int}", Name = "EditorById")]
    public ActionResult Edit(int id)
    

    Then in your view you would use Url.RouteUrl instead of Url.Action:

    @Url.RouteUrl("EditorById", new { controller = "Editor", Id = 1, action = "Edit" })
    

    Hope this helps,

提交回复
热议问题