Hi Destinykid,
Replace the article view code with below.
View
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@model SelectList
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form method="post" asp-controller="Home" asp-action="Index">
<select id="ddlFruits" name="FruitId" asp-items="Model" onchange="fruitChaged(this)">
<option value="0">Please select</option>
</select>
<input type="hidden" name="FruitName" />
<input type="submit" value="Submit" />
<script type="text/javascript">
function fruitChaged(ddlFruits) {
var selectedText = ddlFruits.options[ddlFruits.selectedIndex].innerHTML;
document.getElementsByName("FruitName")[0].value = selectedText;
}
</script>
@if (ViewBag.Message != null)
{
<script type="text/javascript">
window.onload = function () {
alert("@ViewBag.Message");
}
</script>
}
</form>
</body>
</html>