얘들을 PersonID를 전송하고 '보기'를 클릭하면이 사람의 현재 공휴일이 모두 표시됩니다.사용 쿠키들은 '사람 이름을'선택 1 2 일 <p>1</p>) 드롭 다운 상자를 사용하여 작업을 수행 할 수 있습니다, 그래서 기압 다른 페이지로
2) '새로 만들기'를 클릭하면 사용자가 새 휴일을 추가 할 수있는 만들기 페이지로 이동합니다 (여기에서 드롭 다운하여 캘린더에서 원하는 날짜 선택)
이 방법은 모두 작동하지만 사용자가 원래 사람 이름을 선택하고 첫 번째 경로를 클릭하면 (2)의 경로를 취한 다음 '만들기'를 클릭하면 만들기 페이지로 이동합니다. 그러나 드롭 다운 상자가 'select'에서 다시 나타납니다. 이전 드롭 다운에서 선택한 기존 사람을이 드롭 다운에 표시하고 싶습니다.
쿠키 또는 URL/매개 변수?
어쨌든 도와주세요.
쿠키를 사용해 보았습니다.
[code]
[HttpGet]
public ViewResult Index(string sortOrder, int? currentPersonID)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();
if (currentPersonID.HasValue)
{
model.currentPersonID = currentPersonID.Value;
}
else
{
model.currentPersonID = 0;
}
model.PList4DD = db.People.ToList();
//hyperlink to sort dates in ascending order
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : "";
var dates = from d in db.Holidays
where d.PersonId == currentPersonID.Value
select d;
switch (sortOrder)
{
case "date":
dates = dates.OrderBy(p => p.HolidayDate);
break;
}
model.HList4DD = dates.ToList();
var cookie = new HttpCookie("cookie_name", "currentPersonID");
Response.AppendCookie(cookie);
return View(model);
}
public ActionResult Create()
{
var cookie = Request.Cookies["cookie_name"];
if (cookie != null)
{
string value = cookie.Value;
//int? value = cookie.Value;
}
ViewBag.cookie = cookie.Value;
ViewBag.Id = new SelectList(db.People, "Id", "Name");
return View();
}
// int로 색인의 currentPersonID를 사용하려했지만 나를 허용했습니다.
[/code]
My View
[code]
@model HolidayBookingApp.Models.startANDend
@{
ViewBag.Title = "Create";
}
<p>
<span>@ViewBag.cookie</span>
<h2>Create</h2>
<form action ="ListHolidays" id="listHolidays" method="post">
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Holiday</legend>
<div>
@Html.LabelFor(model => model.PersonId, "Person")
</div>
<div>
@Html.DropDownListFor(model => model.PersonId,
new SelectList(ViewBag.Id, "Value", "Text"),
"---Select---"
)
@Html.ValidationMessageFor(model => model.PersonId)
</div>
<div>
@Html.LabelFor(model => model.HolidayDate)
</div>
<div>
@Html.TextBoxFor(model => model.HolidayDate)
@Html.TextBoxFor(model => model.endDate)
<script>
// Date.format = 'dd/m/yyy';
$("#HolidayDate").addClass('date-pick');
$("#endDate").addClass('date-pick');
//$('.date-pick').datePicker//({dateFormat: 'dd-mm-yy'}).val();
// clickInput: true
$(function() {
//3 methods below dont allow user to select weekends
$('.date-pick').datePicker(
{
createButton: false,
renderCallback: function ($td, thisDate, month, year) {
if (thisDate.isWeekend()) {
$td.addClass('weekend');
$td.addClass('disabled');
}
}
}
)
.bind('click',
function() {
$(this).dpDisplay();
this.blur();
return false;
}
)
.bind('dateSelected',
function (e, selectedDate, $td) {
console.log('You selected ' + selectedDate);
}
);
// HolidayDate is start date
$('#HolidayDate').bind('dpClosed',
function (e, selectedDates) {
var d = selectedDates[0];
if (d) {
d = new Date(d);
$('#endDate').dpSetStartDate(d.addDays(0).asString());
}
}
);
//end date is end date
$('#endDate').bind('dpClosed',
function (e, selectedDates) {
var d = selectedDates[0];
if (d) {
d = new Date(d);
$('#HolidayDate').dpSetEndDate(d.addDays(0).asString());
}
}
);
});
</script>
@Html.ValidationMessageFor(model => model.HolidayDate)
</div>
<p>
<input type="submit" value="Create"/>
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@*
<p>Current Person Selected is:
@TempData["currentPersonID"]
</p>*@
[code]
일단 내가 어떻게이 값을 저장하기 위해 내 드롭 다운을 얻을 수 있습니까? 도움이 되었습니까?
감사
나에게
감사합니다. ajp 튜토리얼에 대해 알려 드리겠습니다. – John