I have method called 'Upload' that will receive two parameters (IformFile and a string value) how can i pass the selected item from my dropdown list to my controller which is the string parameter in my method.
<form enctype="multipart/form-data" method="post" asp-controller="Exposure" asp-action="Upload">
<div >
<div >
<select >
<option selected>Choose a Database</option>
<option value="SICS">SICS</option>
<option value="TranslationTable">Translation Table</option>
</select>
</div>
</div>
<div >
<div >
<div >
<input type="file" name="DBTemplate" />
<label for="customFile">Choose file</label>
<i>Only Excel file .xls, .xlsx</i>
</div>
</div>
</div>
<div >
<div >
<div >
<button type="submit" id="submit" name="Submit" >Upload</button>
<button asp-controller="Exposure" asp-action="Index" type="button" data-dismiss="modal">Back to list</button>
</div>
</div>
</div>
</form>
< --- Heres my Method --->
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(IFormFile DBTemplate, string selectedItem)
{
}
CodePudding user response:
in your view:
<select name="somename >
in your action:
public IActionResult Upload(IFormFile DBTemplate,string somename)
{
.......
return View();
}
CodePudding user response:
Add name attribute to bind selectedItem,then you can pass selected item from dropdown list to the controller
<select name="selectedItem" >
<option selected>Choose a Database</option>
<option value="SICS">SICS</option>
<option value="TranslationTable">Translation Table</option>
</select>
result: