|
|
|
วิธีดึงค่าจาก DropDownList ส่งเข้าไปเก็บใน Javascript แล้วส่งกลับไปที่ Controllers เพื่อบันทึกลงฐานข้อมูล |
|
|
|
|
|
|
|
Code (C#)
private UBADBEntities db = new UBADBEntities();
//
// GET: /Application/
public ActionResult Index()
{
Application apps = new Application();
var applications = db.Applications.Include("Position").Include("Position1");
ViewBag.Pos1 = new SelectList(db.Positions, "posID", "posName", apps.Pos1);
ViewBag.Pos2 = new SelectList(db.Positions, "posID", "posName", apps.Pos2);
return View(applications);
}
[HttpPost]
public ActionResult Index(int id, string firstName, string lastName, int firstPosition, int secondPosition, string nickName)
{
var applicationQuery =
from app in db.Applications
where app.CandidateID == id
select app;
ViewBag.Pos1 = new SelectList(db.Positions, "posID", "posName");
ViewBag.Pos2 = new SelectList(db.Positions, "posID", "posName");
foreach (var application in applicationQuery)
{
if (application.CandidateID == id)
{
application.Pos1 = firstPosition;
application.Pos2 = secondPosition;
application.FirstName = firstName.ToString();
application.LastName = lastName.ToString();
application.NickName = nickName.ToString();
}
}
db.SaveChanges();
return View(db.Applications.ToList());
}
Code (JavaScript)
<script type="text/javascript">
function ShowEditButton(par) {
$("#firstName-" + par).attr("class", "invisible")
$("#txtFirstName-" + par).attr("class", "show")
$("#lastName-" + par).attr("class", "invisible")
$("#txtLastName-" + par).attr("class", "show")
$("#firstPosition-" + par).attr("class", "hide")
$("#ddlPos1-" + par).attr("class", "show")
$("#secondPosition-" + par).attr("class", "hide")
$("#ddlPos2-" + par).attr("class", "show")
$("#nickName-" + par).attr("class", "invisible")
$("#txtNickName-" + par).attr("class", "show")
$("#btnEdit-" + par).attr("class", "btn-toolbar text-center btn-group btn hide")
$("#btnSave-" + par).attr("class", "btn-toolbar text-center btn-group btn show")
};
function SaveEditButton(par) {
$("#firstName-" + par).attr("class", "show")
$("#txtFirtsName-" + par).attr("class", "invisible")
$("#lastName-" + par).attr("class", "show")
$("#txtLastName-" + par).attr("class", "invisible")
$("#firstPosition-" + par).attr("class", "show")
$("#ddlPos1-" + par).attr("class", "hide")
$("#secondPosition-" + par).attr("class", "show")
$("#ddlPos2-" + par).attr("class", "hide")
$("#nickName-" + par).attr("class", "show")
$("#txtNickName-" + par).attr("class", "invisible")
$("#btnEdit-" + par).attr("class", "btn-toolbar text-center btn-group btn show")
$("#btnSave-" + par).attr("class", "btn-toolbar text-center btn-group btn hide")
var _firstName = $("#txtFirstName-" + par).val();
var _lastName = $("#txtLastName-" + par).val();
var _firstPosition = $("#ddlPos1-" + par).val();
var _secondPosition = $("#ddlPos2-" + par).val();
var _nickName = $("#txtNickName-" + par).val();
var url = '@Url.Action("Index","Application")';
$.post(url, { id: par, firstName: _firstName, lastName: _lastName, firstPosition: _firstPosition, secondPosition: _secondPosition, nickName: _nickName }, function (data) {
alert(par)
alert(_firstName)
alert(_lastName)
alert(_firstPosition)
alert(_secondPosition)
alert(_nickName)
$("#divResult").html(data);
});
};
</script>
ดึงค่าจาก textbox ได้แต่ดึงจาก list ไม่ได้ครับ ต้องการทำ Edit inline ครับ
Tag : .NET, Ms SQL Server 2008, JavaScript, Web (ASP.NET), C#, VS 2010 (.NET 4.x)
|
|
|
|
|
|
Date :
2013-06-13 17:18:39 |
By :
DevilMonkeyZ |
View :
955 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-06-14 11:45:16 |
By :
DevilMonkeyZ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|