Should be a relatively simple question but currently I'm not able to pass model values updated in the view back to the controller.
As you can see below we have a very simple dropdown list in the view. The 'tenant' string in the Model should be getting set with whichever value is selected in the dropdown list.
However, when clicking on the submit button the 'tenant' string returns null in the controller...
What am I missing?
Thanks!
Model:
public class TenantModel
{
public List<string> tenantList { get; set; }
public string tenant { get; set; }
}
View:
@model TenantModel
@{
ViewData["Title"] = "Manage";
}
<h1>Manage Databases</h1>
@Html.DropDownListFor(m => m.tenant, new SelectList(Model.tenantList), "Select Tenant", new { @class = "dropdown", @style = "width: 220px" })
<br />
<button type="submit" onclick="location.href='@Url.Action("DropDbs", "Environments", Model)'" class="btn btn-danger">Destroy</button>
Controller
public class EnvironmentsController : Controller
{
public IActionResult Manage()
{
var tenantModel = new TenantModel();
tenantModel.tenantList = Utils.TenantList();
return View(tenantModel);
}
public IActionResult DropDbs(TenantModel tenantModel)
{
return RedirectToAction("Manage");
}
}