Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing null parameters
    primarykey
    data
    text
    <p>I am currently having some trouble wrapping my head around this issue. I had a method that didn't require any parameters and now i need to add a parameter but i don't want to add the parameter in all the different places where the method is called. This is my current method : </p> <pre><code>private IEnumerable&lt;SearchItems&gt; GetItems(ItemDescriptionFormViewModel viewModel = null) { IOrderedQueryable&lt;ItemDescription&gt; items= _itemDescriptionRepository.FindAll().OrderBy( c =&gt; c.Sort == null).ThenBy( c =&gt; c.Sort).ThenBy(c =&gt; c.Description); if(items.Count()==0) ModelState.AddModelError("", string.Format("No active {0} entered.", Kids.Resources.Entities.ItemDescription.EntityNamePlural)); return _itemDescriptionRepository.FindAll().OrderBy(c =&gt; c.Description).Where(a=&gt;a.IsActive == true || viewModel == null || a.ItemDescriptionId == viewModel.ItemDescriptionId).Select( c =&gt; new SearchItems {Text = c.Description, Value = c.ItemDescriptionId.ToString()}); } </code></pre> <p>I tried passing in null as a parameter for the other places where this method is being called but i am getting an error. What is the way to overload this issue?</p> <p>PURPOSE: The purpose of adding the viewModel is because i have a dropdown list with active items to choose from. Once a user selects an active item and then for some reason that item becomes inactive and the user goes to edit their selection. In the dropdown list there should be the list of active items along with their previous selected item that is now inactive. I am using the ViewModel to check the id of the previously selected item. </p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload