Using Html.BeginForm to post to the current controller

后端 未结 3 1673
温柔的废话
温柔的废话 2021-01-12 10:37

I have a partial that is used in several views. The partial contains forms. The action when a form is submited is allways the same, but the controller thats contains the act

3条回答
  •  长情又很酷
    2021-01-12 11:09

    ViewContext's RouteData property contains names of current controller and action. You could use them like this:

    Html.BeginForm("ActOnChoosenPerson", ViewContext.RouteData.
        GetRequiredString("controller"))
    

提交回复
热议问题