Try our conversational search powered by Generative AI!

Pass parameter from partialview(block) to view?


Hello and thank you!

I have this block where I authenticate with Facebook. What I want if something wrong occurs I want to pass a parameter from my partialview to a view.

atm I have code like this:

(in psuedo code)

Response.Redirect(signinpage, parameter(sorry something went wrong));

When I get redirected to my view I have the parameter with me. Problem is: How do I write this out on the view?

Let's say that the view is a standardpage.. Should I make a check that if the request contains "sorry" then write it out on the standardpage?

Please any ideas?

// Alexander

Jan 22, 2014 11:32

One of the solution would be that in the block controller if something went wrong you add "flag" to the TempData collection object.

This is object that is specifically designed to survive Redirect operations. So in View or controller you can check whether particular key exists in TempData collection. If it does - you can show error message to the user. And as soon as you will read data from this TempData object - if will disappear from the collection.

Jan 22, 2014 22:25

One thing with TempData that can be good to know about is that by default it is backed by Session (which might not be used at site).

So in cases where you develop a module/addon (that is you cant control if session is used on site or not) you should be careful about using TempData. It is however possible to replace the System.Web.Mvc.ITempDataProvider either at a global level by registering implementation with System.Web.Mvc.IDependencyResolver or for a specific controller by overriding method CreateTempDataProvider() from ControllerBase

Jan 23, 2014 8:11
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.