New to .net core, have an mvc .net core app where I set parameters in a partial view, click a "submit' button and get a list of data returned from CreateList action in my controller. This all works. I added a button "export to excel" and have an ExportToExcel action in the same controller but when I click the "export to excel" button, it goes to the "CreateList" action instead of "ExportToExcel" action.
I've tried input type=Submit and formaction = "CreateList" and "ExportToExcel" respectively. I tried button asp-action=CreateList and button asp-action=ExportToExcel but it always goes to CreateList action
cshtml:
<form asp-controller="CADIncidentData" method="post">
<button asp-action="CreateList" asp-controller="CADIncidentData">View List</button>
<button asp-action="ExportToExcel" asp-controller="CADIncidentData">Export To Excel</button>
</form>
Controller: CallIncidentData
[HttpPost]
public IActionResult CreateList(CallData.allParameters c)
{
...code to create the list
}
[HttpPost]
public IActionResult ExportToExcel(CallData.allParameters c)
{
...code to export to excel
}
I need the asp-action ExportToExcel to go to the ExportToExcel action in my controller, instead of going to "CreateList" in the controller where it is currently going. I don't understand why it's NOT going there, and what can I do to fix it?
答案 0 :(得分:0)
愚蠢的错误-我的实际操作项目没有“公开”字样(我发布的代码已简化为该问题)。添加了公开内容,并且可以使用。