我有一种将数据导出到Excel的方法,称为ExportCSV()。
我想要一种具有附加功能的方法:ExportCSV(string searchString),其中将网页搜索栏中的字符串发送到此方法,然后可以在其中使用它。所以我的问题是,如何将搜索栏中的字符串发送到此方法?
相关代码如下。
html的代表确实有效的搜索功能,但我无法获得类似的功能来进行导出]]
<input type="text" placeholder="Chem Name" name="cheminventory2String" value="@ViewData["Search"]" id="SearchString" /> <input type="submit" value="Search" class="btn btn-default" /> <a class="btn btn-default" asp-action="ExportCSV">Export Table</a>
这里是控制器
public FileContentResult ExportCSV(string searchString) { var dataTable = from m in _context.ChemInventory2.Include(c => c.Chemical).Include(c => Location).Include(c => c.Order) select m; *code for making and filling the csv to export* return File(export.ExportToBytes(), "text/csv", "Chemical Inventory.csv"); }
ExportCSV()有效,但是它导出表中的所有内容。我希望它仅导出已搜索的内容。在我尝试过的事情中,什么都没有传递到方法中。 searchString始终为空。
我有一种将数据导出到Excel的方法,称为ExportCSV()。我想要一种具有附加功能的方法:ExportCSV(string searchString)其中Web上搜索栏中的字符串...
<form method="GET" asp-action="ExportCSV">
<input type="text" placeholder="Chem Name" name="cheminventory2String" value="@ViewData["Search"]" id="SearchString" />
<input type="submit" value="Search" class="btn btn-default" />
<button type="submit" class="btn btn-default">Export Table</a>
</form>