Click here to Skip to main content
       

.NET Framework

 
GeneralRe: OOPS concepts in c# Pinmember95003940023-Dec-12 3:07 
GeneralRe: OOPS concepts in c# PinprotectorPete O'Hanlon3-Dec-12 3:10 
GeneralRe: OOPS concepts in c# PinmvpDave Kreskowiak3-Dec-12 3:22 
GeneralRe: OOPS concepts in c# PinprotectorPete O'Hanlon3-Dec-12 3:24 
GeneralRe: OOPS concepts in c# Pinmember95003940023-Dec-12 3:33 
QuestionTAPI3 Call Id ?? Pinmembertrashambishion30-Nov-12 12:17 
AnswerRe: TAPI3 Call Id ?? PinmemberEddy Vluggen1-Dec-12 0:45 
QuestionDrop down list value returns to ---select--- after page refresh PinmemberxnaLearner30-Nov-12 5:49 
Heys guys
 
So in my application the user will select a name from the drop down list, click 'view' and the corresponding values will display on page.
 
A hyperlink is then used to sort the list in ascending order. For this to happen the page refreshes and displays the new order of the list.
 
The value of the drop down list returns back to its original value of 'select' instead of remaining the name of the person selected.
 
My Model:
 
public class HolidayList
{
public List HList4DD { get; set; }
public List PList4DD { get; set; }
 
public int currentPersonID { get; set; }
public IEnumerable<SelectListItem> Categories { get; set; }
 
public HolidayList()
{
HList4DD = new List();
PList4DD = new List();
}
}
}
----------------------------------------
 
my controller:
 
[HttpPost]
public ViewResult Index(int HolidayDate)
{
var holidays = db.Holidays.Include("Person");
 
HolidayList model = new HolidayList();
 
model.currentPersonID = HolidayDate;
model.PList4DD = db.People.ToList();
model.Categories = holidays.Select(x => new SelectListItem
{
Value = x.Id.ToString(),
Text = x.Person.Name
}
);
 

int data = HolidayDate;
 
model.HList4DD = db.Holidays.Where(h => h.PersonId == HolidayDate).ToList();
 
return View(model);
 
}
 
[HttpGet]
public ViewResult Index(string sortOrder, int? currentPersonID)
{
var holidays = db.Holidays.Include("Person");

HolidayList model = new HolidayList();

//not null
if (currentPersonID.HasValue)
{
model.currentPersonID = currentPersonID.Value;
 
}
else
{
model.currentPersonID = 0;
}
 
model.PList4DD = db.People.ToList();
 
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();
 
return View(model);
}
-----------------------
 
my view
 
i've tried a number of different attempts here, the following code worked but has the drop list problem
 
@Html.DropDownListFor(model => model.HList4DD.First().HolidayDate,
new SelectList(Model.PList4DD, "Id", "Name"),
// Model.currentPersonID
"---Select---"
) *@
 

-----------
 
my attempts to resolve this are:
 
@* @Html.DropDownList("HolidayDate", Model.Categories, "---Select---")*@
 
@* @Html.DropDownListFor("HolidayDate", x => x.HolidayDate, Model.Categories)
*@
------------
 
Any help much appreciated
 
thaks
Questionimage processing Pinmembermarwamekky29-Nov-12 3:52 
AnswerRe: image processing PinmvpDave Kreskowiak30-Nov-12 5:12 
AnswerRe: image processing Pinmember@AmitGajjar2-Dec-12 6:04 
QuestionIIS Server access Pinmember950039400228-Nov-12 19:55 
AnswerRe: IIS Server access PinmemberEddy Vluggen1-Dec-12 0:48 
AnswerRe: IIS Server access Pinmember@AmitGajjar2-Dec-12 6:03 
GeneralRe: IIS Server access Pinmember95003940022-Dec-12 18:03 
AnswerRe: IIS Server access PinmemberAnkitGoel.com10-Dec-12 18:41 
QuestionSystem.Threading.Timer Class Pinmembersaswademayur28-Nov-12 0:40 
AnswerRe: System.Threading.Timer Class PinmvpDave Kreskowiak30-Nov-12 5:11 
GeneralRe: System.Threading.Timer Class Pinmembersaswademayur8-Apr-13 1:24 
QuestionAbout Collections in .NET PinmemberrathmA_27-Nov-12 19:57 
AnswerRe: About Collections in .NET PinprotectorPete O'Hanlon28-Nov-12 1:08 
GeneralRe: About Collections in .NET PinmemberrathmA_28-Nov-12 17:48 
GeneralRe: About Collections in .NET PinprotectorPete O'Hanlon28-Nov-12 22:57 
GeneralRe: About Collections in .NET PinmemberrathmA_6-Dec-12 18:22 
AnswerRe: About Collections in .NET PinmemberEddy Vluggen1-Dec-12 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 26 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid