MVC razor form with multiple different submit buttons?

前端 未结 13 2015
-上瘾入骨i
-上瘾入骨i 2020-12-04 12:59

A Razor view has 3 buttons inside a form. All button\'s actions will need form values which are basically values coming input fields.

Every time I click any of butto

13条回答
  •  孤街浪徒
    2020-12-04 13:37

    Didn't see an answer using tag helpers (Core MVC), so here it goes (for a delete action):

    On HTML:

    @for (var i = 0; i < Model.List.Count(); i++) { }
    @Model.List[i].ItemDescription

    On Controller:

    [HttpPost("[action]/{idForDeleteItem}"), ActionName("Delete")]
    public async Task DeleteConfirmed(long idForDeleteItem)
    {
        ///delete with param id goes here
    }
    

    Don't forget to use [Route("[controller]")] BEFORE the class declaration - on controller.

提交回复
热议问题