I want to Remove/hide the 1st item from the @Html.DropDownListFor
.This dropdown has four items. I want to remove/hide the 1st item only. But those values are not hard cord values, that are retrieved from the object of the model. I haven't so long experience in C# razor pages. Please help me to do that.
<div >
@Html.DropDownListFor(m => m.AdvancedMachingSavedListVM.Where(x => x.CharityException.AdvancedMatchingExceptionType.ID == savedItem.CharityException.AdvancedMatchingExceptionType.ID && x.CharityException.ID == savedItem.CharityException.ID).FirstOrDefault().CharityException.AdvancedMatchingExceptionType.ID, savedType, new { @id = "advancedmachingtype_" @savedItem.CharityException.ID, @class = "ad_select no-p-space medium_dropdown", @onchange = "advancedmachingtypeChanged(" savedItem.CharityException.ID ")" })
</div>
CodePudding user response:
if you want to remove first item of a list you can simply use Skip method like this
//skip first item in list
myList.Skip(1).ToList();
I could not understand the meaning of your code. I hope this code helps you.
CodePudding user response:
you can do it with jquery when the razor page is loaded within document.ready()
$("#advancedmachingtype_ option[value=" title "]").hide();
title will be the first index of dropdownlist