Click here to Skip to main content
15,888,968 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: OOPS concepts in c# Pin
95003940023-Dec-12 2:07
95003940023-Dec-12 2:07 
GeneralRe: OOPS concepts in c# Pin
Pete O'Hanlon3-Dec-12 2:10
mvePete O'Hanlon3-Dec-12 2:10 
GeneralRe: OOPS concepts in c# Pin
Dave Kreskowiak3-Dec-12 2:22
mveDave Kreskowiak3-Dec-12 2:22 
GeneralRe: OOPS concepts in c# Pin
Pete O'Hanlon3-Dec-12 2:24
mvePete O'Hanlon3-Dec-12 2:24 
GeneralRe: OOPS concepts in c# Pin
95003940023-Dec-12 2:33
95003940023-Dec-12 2:33 
QuestionTAPI3 Call Id ?? Pin
trashambishion30-Nov-12 11:17
trashambishion30-Nov-12 11:17 
AnswerRe: TAPI3 Call Id ?? Pin
Eddy Vluggen30-Nov-12 23:45
professionalEddy Vluggen30-Nov-12 23:45 
QuestionDrop down list value returns to ---select--- after page refresh Pin
xnaLearner30-Nov-12 4:49
xnaLearner30-Nov-12 4: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 2:52
shiningstat29-Nov-12 2:52 
AnswerRe: image processing Pin
Dave Kreskowiak30-Nov-12 4:12
mveDave Kreskowiak30-Nov-12 4:12 
AnswerRe: image processing Pin
AmitGajjar2-Dec-12 5:04
professionalAmitGajjar2-Dec-12 5:04 
QuestionIIS Server access Pin
950039400228-Nov-12 18:55
950039400228-Nov-12 18:55 
AnswerRe: IIS Server access Pin
Eddy Vluggen30-Nov-12 23:48
professionalEddy Vluggen30-Nov-12 23:48 
AnswerRe: IIS Server access Pin
AmitGajjar2-Dec-12 5:03
professionalAmitGajjar2-Dec-12 5:03 
GeneralRe: IIS Server access Pin
95003940022-Dec-12 17:03
95003940022-Dec-12 17:03 
AnswerRe: IIS Server access Pin
AnkitGoel.com10-Dec-12 17:41
AnkitGoel.com10-Dec-12 17:41 
QuestionSystem.Threading.Timer Class Pin
saswademayur27-Nov-12 23:40
saswademayur27-Nov-12 23:40 
AnswerRe: System.Threading.Timer Class Pin
Dave Kreskowiak30-Nov-12 4:11
mveDave Kreskowiak30-Nov-12 4:11 
GeneralRe: System.Threading.Timer Class Pin
saswademayur8-Apr-13 0:24
saswademayur8-Apr-13 0:24 
QuestionAbout Collections in .NET Pin
Leisvan Cordero27-Nov-12 18:57
Leisvan Cordero27-Nov-12 18:57 
AnswerRe: About Collections in .NET Pin
Pete O'Hanlon28-Nov-12 0:08
mvePete O'Hanlon28-Nov-12 0:08 
GeneralRe: About Collections in .NET Pin
Leisvan Cordero28-Nov-12 16:48
Leisvan Cordero28-Nov-12 16:48 
GeneralRe: About Collections in .NET Pin
Pete O'Hanlon28-Nov-12 21:57
mvePete O'Hanlon28-Nov-12 21:57 
GeneralRe: About Collections in .NET Pin
Leisvan Cordero6-Dec-12 17:22
Leisvan Cordero6-Dec-12 17:22 
AnswerRe: About Collections in .NET Pin
Eddy Vluggen1-Dec-12 5:44
professionalEddy Vluggen1-Dec-12 5: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.