在文本框中显示下拉列表选定的数据。

问题描述:

查看页面



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>





这是.cshtml查看代码 -





And this is the .cshtml view code-

<div class="editor-label">
@Html.LabelFor(model =&gt; 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();
}





我的问题是当我插入数据时,Convert.ToInt32(Empmasters)的值显示Name Not id。想插入ID。它显示错误。



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.

(文件).ready(function()
(document).ready(function ()


(#Empmasters )。change(function(){
("#Empmasters").change(function () {


(#Text1)。val(
("#Text1").val(