Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to return a view with querystring parameters in MVC5?

Very basic but not sure how to do since i am new to mvc.

I have to return a view based on a if condition.

if true, i should return a view with a guid value as querystring parameter else return a different view.

public ActionResult Act(Guid approvalCode)
    {
        bool result = businessProvider.CheckLinkValidity(approvalCode);
        if (result == true)
        {
            return View("Act"); //here i need to pass approvalcode as querystring param
          //want to do like
          //return View("Act"+"?code="+approvalcode) 
        }
        return View("LinkExpiredView");
    }

I need to render the view like:

~\ResetController\Act?code= someguidvalue

like image 685
kaarthick raman Avatar asked Dec 19 '22 15:12

kaarthick raman


1 Answers

I actually don't understand why you need query string.

Without it you can do like this:

return View("Act", new { code = "your-guid" });

If you still need it one of possible ways RedirectToAction method:

return RedirectToAction("Act", new { code = "your-guid" });
like image 129
teo van kot Avatar answered Dec 24 '22 01:12

teo van kot