Click here to Skip to main content
14,358,347 members

.NET Framework

 
GeneralRe: OOPS concepts in c# Pin
95003940023-Dec-12 3:07
member95003940023-Dec-12 3:07 
GeneralRe: OOPS concepts in c# Pin
Pete O'Hanlon3-Dec-12 3:10
protectorPete O'Hanlon3-Dec-12 3:10 
GeneralRe: OOPS concepts in c# Pin
Dave Kreskowiak3-Dec-12 3:22
mveDave Kreskowiak3-Dec-12 3:22 
GeneralRe: OOPS concepts in c# Pin
Pete O'Hanlon3-Dec-12 3:24
protectorPete O'Hanlon3-Dec-12 3:24 
GeneralRe: OOPS concepts in c# Pin
95003940023-Dec-12 3:33
member95003940023-Dec-12 3:33 
QuestionTAPI3 Call Id ?? Pin
trashambishion30-Nov-12 12:17
membertrashambishion30-Nov-12 12:17 
AnswerRe: TAPI3 Call Id ?? Pin
Eddy Vluggen1-Dec-12 0:45
mveEddy Vluggen1-Dec-12 0:45 
QuestionDrop down list value returns to ---select--- after page refresh Pin
xnaLearner30-Nov-12 5:49
memberxnaLearner30-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<holiday> HList4DD { get; set; }
public List<person> PList4DD { get; set; }

public int currentPersonID { get; set; }
public IEnumerable<SelectListItem> Categories { get; set; }

public HolidayList()
{
HList4DD = new List<holiday>();
PList4DD = new List<person>();
}
}
}
----------------------------------------

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 Pin
shiningstat29-Nov-12 3:52
membershiningstat29-Nov-12 3:52 
AnswerRe: image processing Pin
Dave Kreskowiak30-Nov-12 5:12
mveDave Kreskowiak30-Nov-12 5:12 
AnswerRe: image processing Pin
AmitGajjar2-Dec-12 6:04
professionalAmitGajjar2-Dec-12 6:04 
QuestionIIS Server access Pin
950039400228-Nov-12 19:55
member950039400228-Nov-12 19:55 
AnswerRe: IIS Server access Pin
Eddy Vluggen1-Dec-12 0:48
mveEddy Vluggen1-Dec-12 0:48 
AnswerRe: IIS Server access Pin
AmitGajjar2-Dec-12 6:03
professionalAmitGajjar2-Dec-12 6:03 
GeneralRe: IIS Server access Pin
95003940022-Dec-12 18:03
member95003940022-Dec-12 18:03 
AnswerRe: IIS Server access Pin
AnkitGoel.com10-Dec-12 18:41
memberAnkitGoel.com10-Dec-12 18:41 
QuestionSystem.Threading.Timer Class Pin
saswademayur28-Nov-12 0:40
membersaswademayur28-Nov-12 0:40 
AnswerRe: System.Threading.Timer Class Pin
Dave Kreskowiak30-Nov-12 5:11
mveDave Kreskowiak30-Nov-12 5:11 
GeneralRe: System.Threading.Timer Class Pin
saswademayur8-Apr-13 1:24
membersaswademayur8-Apr-13 1:24 
QuestionAbout Collections in .NET Pin
Leisvan Cordero27-Nov-12 19:57
memberLeisvan Cordero27-Nov-12 19:57 
AnswerRe: About Collections in .NET Pin
Pete O'Hanlon28-Nov-12 1:08
protectorPete O'Hanlon28-Nov-12 1:08 
GeneralRe: About Collections in .NET Pin
Leisvan Cordero28-Nov-12 17:48
memberLeisvan Cordero28-Nov-12 17:48 
GeneralRe: About Collections in .NET Pin
Pete O'Hanlon28-Nov-12 22:57
protectorPete O'Hanlon28-Nov-12 22:57 
GeneralRe: About Collections in .NET Pin
Leisvan Cordero6-Dec-12 18:22
memberLeisvan Cordero6-Dec-12 18:22 
AnswerRe: About Collections in .NET Pin
Eddy Vluggen1-Dec-12 6:44
mveEddy Vluggen1-Dec-12 6:44 

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

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