.net Core select dropdown is very slow - asp.net-core

In my website, I have got 2 select dropdown list Client and Staff.
I have got roughly 100 Clients and 350 Staffs.
Populating dropdown list is very slow. for example for the staff dropdown list takes around 40sec and little less for Client. basically it takes 1 minuted to load the page.
First I used ViewData
ViewData["EmployeeList"] = new SelectList(employeeRepository.Employees.,"EmployeeID", "FullName");
cshtm
<select asp-for="EmployeeID" class="form-control col-sm-12" asp-items="ViewBag.EmployeeList"></select>
Then I changed it to ViewModel
EmplSelectList = new SelectList(employeeRepository.Employees, "EmployeeID", "FullName")
cshtml
<select asp-for="ClientID" class="form-control col-sm-12" asp-items="Model.ClientSelectList"></select>
This didn't improve much.
Does anyone know a better way to solve this issue? Please.
Thanks advance for help.

Related

Get selected value from dropdown while bininding it with razor foreach

I am binding dropdown like below
<select id="example1">
#foreach (var item in Model)
{
<option value=#item.Id data-image=#item.Document_Page_URL>Image</option>
}
</select>
Actually client is using some plugins as you can see data-image in option tag this is the only option to bind images and i have done that,
now i want to get selected value from this dropdown, it would be better if i could post (using searlize methode) value using my ViewModel please help ,
NOTE I am newbie in MVC so please ignore if i am wrong any where in question, Also if any one can suggest me a method in mvc to bind images to #Html.Dropdownfor() will be appreciated
You can use #Html.DropDownListFor() and set value="#item.Id"

How to populate a webform variable

I'm attempting to use VB.Net WebBorwser to populate and submit a webform. I'm using webbrowser because I don't know much javascript or c#. I'm open to other ideas of course.
I'm able to populate the form fields easily enough:
m_oWebBrowser1.Document.GetElementById("line1").SetAttribute("value", "Flat 12")
but this isn't enough to trigger the page to set the require variables. I've also tried:
m_oWebBrowser.Document.GetElementById("line1").InvokeMember("change")
and
m_oWebBrowser.Navigate("javascript: PreviousAddress().Address().Line1='Flat 19';")
The input field looks like this:
<input id="previousAddressLine1" class="col-xs-12 col-sm-8" name="previousAddressLine1" tabindex="12" data-bind="value: PreviousAddress().Address().Line1" type="text">
Any help would be great.
-Ben

Change maxlength based on name="..." Possible?

I'll admit, I'm new to this world. Im working on my first site, which has a template file setup. In the template I have a code thats similar to
<input type="text" name="option[**]"/>
Where Option[**] is pulled from somewhere else, heres my issue;
Is there something I can do to limit the text input length based on the option number pulled? I did a
<input maxlength=10 type="text" name="option[**]"/>
and that worked to limit all my text input boxes there to 10, however I have say Option[1] and option[2]; I want 1 limited to 10 and 2 limited to 15. is this possible? remember, Im new to all this :)

How to bind Listbox (select size="n") item values to IEnumerable<int>

I have a select element on my form. I fill its contents with javascript. The view model has a property called Fruits of type IEnumerable. Is it possible to bind this select to that property when I submit the form? So to make it clear, assume there's a form with a select of size 5, which at the same time is empty. Then I add some items (options) to that select with java script:
<select size="5">
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Grape</option>
<option value="4">Pinapple</option>
</select>
When I submit the form, I want the Fruits property to contain the above option values. How's that done? I can't think of any way to do it.
Finally found it, something's missing though. To overcome the first problem of getting an empty ListBox on the view I did this:
ListBoxFor(x=>x.Fruits,new List<SelectListItem>(),new{style="width:160px;display:block"})
This will bring up an empty <select multiple="multiple" size="5" name="Fruits"> to the view. Then I add some items to the listbox with javascript (to be precise, add options to the select). The biggest pain started after this. When submitting the form the Fruits property was null, so listbox items were not getting bound. After lots of digging I discovered that in order for a ListBox items to bind to some collection the desired ones need to be selected. So even if there're 10 items in the listbox, they won't get bound to my Fruits model property unless I select them before submitting. After selecting the added items the Fruits property contained the corresponding values. However I hate to have to select all the items after adding them. I know this can be done automatically with javascript, but it'd be good to bypass this by some other means.

Unable to click the elements in the dynamical list

For the below code
<li class="user ui-menu-item" role="presentation">
<a id="ui-id-52" class="ui-corner-all" tabindex="-1">
<em>User:</em>
Staff User
</a>
</li>
This is the scenario:
There is a text field, in which I enter the name Staff, with that the related values for the staff are displayed in the dynamic list box, in the above scenario the id is dynamically generated, and when I tried to select the value by class, it is same for all the elements.
I want an xpath expression to select the first available options in the list. I tried in many ways like with contains and starts-with, but no use. Please let me know your valuable suggestion.
Thanks in Advance
Shiva.
I think this should work
WebElement ele = webdriver.findElement(By.Xpath("//li[#class='user ui-menu-item'][1]"))
Did you try forming a List and then just directly using the first element of that List?
List<WebElement> list = driver.findElements(By.xpath("//li[#class(contains, 'user')]";
list[0].getText();
I'm still not 100% percentage sure what you want to do with the element once you have found it though. It would probably be better to form the List, then iterate over that list and perform whatever action you require per element.
Use this xpath
"(.//a[#class='ui-corner-all'])[1]"
source: XPath query to get nth instance of an element
Use the xpath. It should work
//li[#role = 'presentation']//a[1]