Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# Choose a return method ActionResult

c# asp.net mvc razor excel actionresult

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 thebigbear

thebigbear

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 17 November 2015 - 02:19 PM

Hello all,
I am working on a MVC project, I currently finished three different excel sheets and depending on the type of insurance the user selects a certain default excel sheet format should be used for that insurance.
Currently I can only select one format in the return statement. What I was trying to do is have an if condition depending the string context to decide what excel format to use.
 
public ActionResult GenerateTripLog(int driverId, int vehicleId, int typeId, int customerId)
{
            try
            {
                var results = (from s in db.usp_TripLog(driverId, vehicleId, typeId, customerId, sDate, eDate) 
                               select s).ToList();

                var driver = new DriverRepository(GetCurrentUser()).GetDriver(driverId);
                var iType = db.insurancetypes.SingleOrDefault(c => c.id == typeId);
                var tenant = GetTenant(GetCurrentUser());                
                var period = "All";           

                var driverSignature = 
                                (from s in driver.driveravailabilityevents
                                where
                                orderby s.createdon descending
                                select s.signature).FirstOrDefault();

                object[] filterStrs =   
                {
                    tenant == null ? "All" : tenant.tenantname,
                    period,
                    driver == null || driver.person == null ? "All" : driver.person.fullname,
                    iType == null ? "All" : iType.name,
                    driverSignature
                };
          //THIS IS WHAT I WAS TRYING TO DO THE SELECTION
                string insuranceType = Convert.ToString(iType);
                if(insuranceType == "FAMILY CARE")
                {
                    return TripLogSpreadsheet(results, filterStrs);
                }
                else if(insuranceType == "BELLIN")
                {
                    return BELLINLogSpreadsheet(results, filterStrs);
                }

      //return TripLogSpreadsheet(results, filterStrs);
      }
      catch (Exception ex)
      {
            ViewData["errormessage"] = ex.Message;
            return View("Error");
      }
}

 



#2 Blimp

Blimp

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 199 posts

Posted 30 November 2015 - 07:22 AM

You need to make sure that TripLogSpreadsheet and BELLINLogSpreadsheet both have return types of ActionResult. If they do, this should work :-)