это код, который я использую, хотел бы знать, есть ли какая-либо работа вокруг этого
public ActionResult Create()
{
ViewBag.employee_no = new SelectList(db.master_file, "employee_no", "employee_name");
ViewBag.employee_name = new SelectList(db.master_file, "employee_no", "employee_no");
return View();
}
// POST: emirates_id/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,employee_no,eid_no,eid_expiry")] emirates_id emirates_id)
{
if (ModelState.IsValid)
{
db.emirates_id.Add(emirates_id);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.employee_no = new SelectList(db.master_file, "employee_no", "employee_name", emirates_id.id);
ViewBag.employee_name = new SelectList(db.master_file, "employee_no", "employee_no", emirates_id.id);
return View(emirates_id);
}
приведенного выше кода, если используется контроллер
<script>
function myFunction() {
var x = document.getElementById("employee_no").value;
document.getElementById("demo").innerHTML = "employee no :" + x;
}
function myFunction2() {
var x = document.getElementById("employee_name").value;
document.getElementById("demo1").innerHTML = "employee name :" + x;
}
используемый скриптдля отображения выбранного значения
<div
class="form-group">
<div class="row">
@Html.LabelFor(model => model.employee_no, "employee_name", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-4">
@Html.DropDownList("employee_no",null, new { @class = "form-control", @id = "employee_no", @OnChange = "myFunction();" })
<p id="demo"></p>
@Html.ValidationMessageFor(model => model.employee_no, "", new { @class = "text-danger" })
</div>
<div class="col-md-4">
<div>
@Html.DropDownList("employee_name", null, new { @class = "form-control", @id = "employee_name", @OnChange = "myFunction2();" })
<p id="demo1"></p>
@Html.ValidationMessageFor(model => model.employee_no, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
просмотреть код, поэтому я хотел бы, если вы поможете мне сделать это