5

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

kaarthick raman
  • 793
  • 2
  • 13
  • 41

2 Answers2

12

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" });
teo van kot
  • 12,350
  • 10
  • 38
  • 70
0

You can also use ViewBag to set some value https://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.viewbag(v=vs.118).aspx

Ktt
  • 469
  • 3
  • 8
  • 18