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

1
  • Instead of query string, you can set the value of your GUID into viewbag and access it your view. ViewBag.GuidVariable = Guid_Value; Commented Jul 19, 2016 at 6:55

2 Answers 2

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" });
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the response. But RedirectToAction doesn't work.
This is the best answer
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.