传递空参数 [英] passing null parameters

查看:51
本文介绍了传递空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在解决这个问题时遇到了一些麻烦.我有一个不需要任何参数的方法,现在我需要添加一个参数,但是我不想在调用该方法的所有不同位置添加该参数.这是我目前的方法:

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 :

private IEnumerable<SearchItems> GetItems(ItemDescriptionFormViewModel viewModel = null)
    {
        IOrderedQueryable<ItemDescription> items= _itemDescriptionRepository.FindAll().OrderBy(
            c => c.Sort == null).ThenBy(
                c => c.Sort).ThenBy(c => c.Description);

        if(items.Count()==0)
            ModelState.AddModelError("", string.Format("No active {0} entered.", Kids.Resources.Entities.ItemDescription.EntityNamePlural));
       return
            _itemDescriptionRepository.FindAll().OrderBy(c => c.Description).Where(a=>a.IsActive == true || viewModel == null || a.ItemDescriptionId == viewModel.ItemDescriptionId).Select(
                c => new SearchItems {Text = c.Description, Value = c.ItemDescriptionId.ToString()});
    }

我尝试在其他调用此方法的地方传递null作为参数,但出现错误.用什么方法可以使此问题超载?

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?

目的:添加viewModel的目的是因为我有一个下拉列表,其中有活动项可供选择.一旦用户选择了一个活动项目,然后由于某种原因该项目变为非活动状态,并且用户去编辑他们的选择.在下拉列表中,应该有活动项的列表以及它们先前不活动的先前选择的项.我正在使用ViewModel来检查先前选择的项目的ID.

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.

谢谢

推荐答案

每个人...感谢您为解决此问题所做的所有帮助和努力.我终于可以解决它,这是我解决问题的人:检查列表项ID

Everyone... Thanks for all the help and effort in trying to resolve this issue. I was finally able to work around it and here is who i fixed my problem: Checking List Item Id

这篇关于传递空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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