How can I simplify these if/else clauses? I have a few if, else-if, else clauses.  The only different thing in the context of these clauses is my LINQ query, one clause has StartsWith, one clause has Contains, and the other does a simple match.  Is there a way to have all of this in one clause and somehow create a variable that can change between StartsWith, Contains, etc.?  My ultimate goal is to reduce the lines of code.

if (parameters[0].ToUpper() == "STARTSWITH" &amp;&amp; parameters[1] != null)
    {
        string searchname = parameters[1];
        ViewBag.MyMessage = "Displaying device names beginning with \"" + searchname + "\"";

        SampleEntities sampleEntities = new SampleEntities();

        try
        {
            var Model = (from dev in sampleEntities.NetworkDevices
                         where dev.Name.StartsWith(searchname)
                         from inter in sampleEntities.DeviceInterfaces
                         where inter.NetworkDevice.Id == dev.Id
                         select new DeviceInterfaceModel
                         {
                             DeviceName = dev.Name,
                             InterfaceName = inter.Name,
                             IPv4Address = inter.IPv4Address,
                             IPv4SubnetMask = inter.IPv4SubnetMask,
                             CIDR = inter.CIDR,
                             Subnet = inter.Subnet
                         }).ToList();

            return View(Model);
        }
        catch
        {
        }

        return View();
    }
    #endregion
    #region Name Contains
    else if (parameters[0].ToUpper() == "CONTAINS" &amp;&amp; parameters[1] != null)
    {
        string searchname = parameters[1];
        ViewBag.MyMessage = "Displaying device names containing \"" + searchname + "\"";

        SampleEntities sampleEntities = new SampleEntities();

        try
        {
            var Model = (from dev in sampleEntities.NetworkDevices
                         where dev.Name.Contains(searchname)
                         from inter in sampleEntities.DeviceInterfaces
                         where inter.NetworkDevice.Id == dev.Id
                         select new DeviceInterfaceModel
                         {
                             DeviceName = dev.Name,
                             InterfaceName = inter.Name,
                             IPv4Address = inter.IPv4Address,
                             IPv4SubnetMask = inter.IPv4SubnetMask,
                             CIDR = inter.CIDR,
                             Subnet = inter.Subnet
                         }).ToList();

            return View(Model);
        }
        catch
        {
        }

        return View();
    }
    #endregion
}

else
{
    ViewBag.MyMessage = "Diplaying device names equal to \"" + name + "\"";
    SampleEntities sampleEntities = new SampleEntities();

    try
    {
        var Model = (from dev in sampleEntities.NetworkDevices
                     where dev.Name == name
                     from inter in sampleEntities.DeviceInterfaces
                     where inter.NetworkDevice.Id == dev.Id
                     select new DeviceInterfaceModel
                     {
                         DeviceName = dev.Name,
                         InterfaceName = inter.Name,
                         IPv4Address = inter.IPv4Address,
                         IPv4SubnetMask = inter.IPv4SubnetMask,
                         CIDR = inter.CIDR,
                         Subnet = inter.Subnet
                     }).ToList();

        return View(Model);
    }
    catch
    {
    }

    return View();
}
This should be more simplified and more clear, now we make the query to the devices context first, then we get the result, instead of repeating the same thing three times. Remember, always use using when dealing with objects that inherits IDisposable:

using (SampleEntities sampleEntities = new SampleEntities())
{
    string searchname = parameters[1];

    var devices = (from dev in sampleEntities.NetworkDevices
        select dev);

    if (parameters[0].ToUpper() == "STARTSWITH" 
        &amp;&amp; parameters[1] != null)
    {
        ViewBag.MyMessage = "Displaying device names beginning with \"" + searchname + "\"";
        devices = (from dev in devices 
            where dev.Name.StartsWith(searchname));
    }
    else if (parameters[0].ToUpper() == "CONTAINS" 
        &amp;&amp; parameters[1] != null)
    {
        ViewBag.MyMessage = "Displaying device names containing \"" + searchname + "\"";
        devices = (from dev in devices 
            where dev.Name.Contains(searchname));
    }   
    else
    {
        ViewBag.MyMessage = "Diplaying device names equal to \"" + name + "\"";
        devices = (from dev in devices 
            where dev.Name == name);
    }

    var Model = (from dev in devices
                 from inter in sampleEntities.DeviceInterfaces
                 where inter.NetworkDevice.Id == dev.Id
                 select new DeviceInterfaceModel
                 {
                     DeviceName = dev.Name,
                     InterfaceName = inter.Name,
                     IPv4Address = inter.IPv4Address,
                     IPv4SubnetMask = inter.IPv4SubnetMask,
                     CIDR = inter.CIDR,
                     Subnet = inter.Subnet
                 })
    .ToList();

    return View(Model);
}