如何防止下拉以显示数据库中的值

时间:2022-02-08 07:26:34

I want to prevent the value of the dropdown list when it is already in the database file so that theres no multiple input in the Database ,

我想在数据库文件中已经存在的情况下阻止下拉列表的值,以便数据库中没有多个输入,

I hope someone can Help me with this problem ,

我希望有人可以帮我解决这个问题,

I'm using MVC 3 and Kendo UI

我正在使用MVC 3和Kendo UI

is that possible to handle it via Jquery or a Linq Statement in the Controller ?

是可以通过Jquery或Controller中的Linq语句来处理它吗?

Thanks :)

谢谢 :)

 <span>
                @Html.DropDownList("ddlDay", new SelectList(ViewBag.DayList, "ID", "Display_Value", PersonDay), "[Please Select]",
          new Dictionary<string, object>
                {
                    {"class","validate[required] inputLong"}
                })
            </span>

This Dropdown Show Monday to Sunday , i have 2 of this drop down that shows availability But i like to know that if i save Monday to Wednesday , Monday to Wednesday is removed on the two dropdowns ,

这个下拉显示周一到周日,我有2个下降显示可用性但我想知道,如果我保存周一至周三,周一至周三将删除两个下拉菜单,

private void GetDayList()
        {
            var dayList = (from a in db.Lookups
                              where a.Domain == "DAYSTATUS"
                              select a).ToList();

            ViewBag.DayList = dayList ;
        }

1 个解决方案

#1


1  

You can solve this in many ways, it will depend on how your interaction is done.

您可以通过多种方式解决此问题,具体取决于您的交互方式。

You could use LINQ, adding a Where() or Except() statement to filter the full list:

您可以使用LINQ,添加Where()或Except()语句来过滤完整列表:

var fromDayList = dayList.Where(day => day.Name != selectedFromDay).ToList();
// or if multiple selected days, assuming it is of the same type:
var validDayList = dayList.Except(selectedDayList).ToList();

If you allow them to change the selected days client side and are using AJAX (which is how you usually use Kendo UI) then you won't want to filter server side. Instead you should wrap your DayList in a kendo.DataSource and apply a filter based on selected days in your JavaScript. You haven't provided enough information for me to supply any sample code for this.

如果您允许他们更改所选日期客户端并使用AJAX(这是您通常使用Kendo UI的方式),那么您不希望过滤服务器端。相反,您应该将您的DayList包装在kendo.DataSource中,并根据JavaScript中的选定日期应用过滤器。您没有提供足够的信息来为我提供任何示例代码。

#1


1  

You can solve this in many ways, it will depend on how your interaction is done.

您可以通过多种方式解决此问题,具体取决于您的交互方式。

You could use LINQ, adding a Where() or Except() statement to filter the full list:

您可以使用LINQ,添加Where()或Except()语句来过滤完整列表:

var fromDayList = dayList.Where(day => day.Name != selectedFromDay).ToList();
// or if multiple selected days, assuming it is of the same type:
var validDayList = dayList.Except(selectedDayList).ToList();

If you allow them to change the selected days client side and are using AJAX (which is how you usually use Kendo UI) then you won't want to filter server side. Instead you should wrap your DayList in a kendo.DataSource and apply a filter based on selected days in your JavaScript. You haven't provided enough information for me to supply any sample code for this.

如果您允许他们更改所选日期客户端并使用AJAX(这是您通常使用Kendo UI的方式),那么您不希望过滤服务器端。相反,您应该将您的DayList包装在kendo.DataSource中,并根据JavaScript中的选定日期应用过滤器。您没有提供足够的信息来为我提供任何示例代码。