Please help me. I need to get the value of the textbox and the value of the dropdown list.
So far i was able to get the value of the dropdown list using this code
public class DropdownOrder
{
public int Id { get; set; }
public string Value { get; set; }
}
public class DropdownOrderVM
{
public int DropdownId { get; set; }
public string SearchValue { get; set; }
public List<DropdownOrder> DropdownList { get; set; }
}
public async Task<ActionResult> Index()
{
var vm = new DropdownOrderVM();
vm.DropdownList = new List<DropdownOrder>
{
new DropdownOrder { Id = 1, Value = "1" },
new DropdownOrder { Id = 2, Value = "2" },
new DropdownOrder { Id = 3, Value = "3" }
};
return View(vm);
}
And this is the view code
<select class="form-control" asp-for="DropdownId"
asp-items="@(new SelectList(Model.DropdownList,"Id","Value"))">
<option>Please select one</option>
</select>
<input type="search" name="search" id="search" asp-for="SearchValue" placeholder="Search" class="form-control" aria-label="Search">
and this is my controller which call called when the button submit is clicked
[HttpPost]
public ActionResult Create(DropdownOrderVM model)
{
return View();
}
I can only get the value of the dropdown. But i added the code in the view
<input type="search" name="search" id="search" asp-for="SearchValue" >
So why does my code doesn't return the user input in the textbox?
What did i do wrong?
name="search",or you can change toname=SearchValue,it will work.