Hhi 65sametkaya65,
Refer below code.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "Select", Value = "0" });
items.Add(new SelectListItem { Text = "John Hammond", Value = "1" });
items.Add(new SelectListItem { Text = "Mudassar Khan", Value = "2" });
ViewBag.name = items;
return View();
}
}
View
<table>
<tr>
<td>
@Html.DropDownList("Name", (List<SelectListItem>)ViewBag.name, new { @class = "form-control" })
</td>
<td>
<input id="txtName" type="text" class="form-control" name="Name" placeholder="Name" />
</td>
</tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#Name").on("change", function () {
$("#txtName").val("").removeAttr('readonly');
if ($(this).val() != "0") {
$("#txtName").val($(this).find('option:selected').text());
$("#txtName").attr('readonly', true);
}
});
});
</script>
Screenshot