view page
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
$("#Empmasters").change(function () {
$("#Text1").val($("#Empmasters option:selected").text());
});
});
</script>
And this is the .cshtml view code-
<div class="editor-label">
@Html.LabelFor(model => model.Empid)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Empid)*@
//@Html.DropDownList("attemp", ViewBag.attemp as SelectList, "-Select Emp ID-", new { id="EmpID"
@Html.DropDownList("Empmasters", null, "--select----", new { @class = "dropdown" })
})
@Html.ValidationMessageFor(model => model.Empid)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Ename)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Ename, new {id="name"})
<input id="Text1" name="Text1" type="text" />
@Html.ValidationMessageFor(model => model.Ename)
</div>
action method-
[HttpGet]
public ActionResult show()
{
ViewBag.attemp = new SelectList(db.Empmasters, "Emp_Name", "Emp_Id");
return View();
}
[HttpPost]
public ActionResult show(Models.att att ,string Empmasters, string Text1)
{
Empat ea = new Empat();
ea.AttID = att.Attid;
ea.Emp_Id = Convert.ToInt32(Empmasters);
ea.Emp_Name = Text1;
ea.Dept = att.dept;
ea.AttendMonth = att.attmonth;
ea.AttendDate = att.attdate;
ea.AttendanceType = att.atttype;
db.EmpAttends.InsertOnSubmit(ea);
db.SubmitChanges();
return view();
}
My question is when i insert data the value of Convert.ToInt32(Empmasters) is showing Name Not id.want to insert ID.It shows error.