Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not all paths return a value. - Optional return?

I am getting the error "Not all paths return a value", and I totally understand why.

As you can see I want to redirect the person isn't logged in, and obviously there is no return view.

I'm sure I'm going about this incorrectly. How should I be trying to do this?

    public ActionResult Confirmation (Order Order) {
        if (Session["CompanyID"] == null)
        {
            string url = Request.Url.Host;
            if (Request.Url.Port != null)
            {
                url = url + Request.Url.Port;
            }
            url = url + "/signin.asp";
            Response.Redirect(url);


        }
        else
        {

            int userID = (int)Session["CompanyID"];
            Corp_User User = Repository.CorpUserDetails(userID);

            return View(new OrderLocation { Order = Order, Location = WhygoRepository.RoomDetails(Order.roomId).First(), Corp_User = User });
        }


    }

Please note that I need to redirect to a classic ASP page, not an MVC action..

like image 607
iKode Avatar asked Aug 02 '26 06:08

iKode


1 Answers

You must return a ActionResult. Use "RedirectToAction".

    public ActionResult Confirmation(Order Order)
    {
        if (Session["CompanyID"] == null)
        {
            string url = Request.Url.Host;
            if (Request.Url.Port != null)
            {
                url = url + Request.Url.Port;
            }
            url = url + "/signin.asp";
            return RedirectToAction(<YOUR ACTION>);


        }
        else
        {

            int userID = (int)Session["CompanyID"];
            Corp_User User = Repository.CorpUserDetails(userID);

            return View(new OrderLocation { Order = Order, Location = WhygoRepository.RoomDetails(Order.roomId).First(), Corp_User = User });
        }


    }
like image 118
dknaack Avatar answered Aug 03 '26 19:08

dknaack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!