下拉列表值返回---选择---页面刷新后 [英] Drop down list value returns to ---select--- after page refresh

查看:66
本文介绍了下拉列表值返回---选择---页面刷新后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们......不确定我是否在论坛的这一部分,但任何... ...

Hi guys..not sure if im in the part of the forums here but anywho...


Heys guys

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.


下拉列表的值返回其原始值'select',而不是保留所选人员的姓名。

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

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

thaks

推荐答案

ASP.NET MVC论坛
http://forums.asp.net/1146.aspx
是这类问题的最好地方
The ASP.NET MVC forums http://forums.asp.net/1146.aspx is the better place for such questions


这篇关于下拉列表值返回---选择---页面刷新后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆