Propagating QueryString parameter in RedirectToAction calls

public class PreserveQueryStringAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { var redirectResult = filterContext.Result as RedirectToRouteResult; if (redirectResult == null) { return; } var query = filterContext.HttpContext.Request.QueryString; // Remark: here you could decide if you want to propagate all // query string values or a particular one. In my example I am // … Read more

Asp.Net core Tempdata and redirecttoaction not working

TempData uses Session, which itself uses IDistributedCache. IDistributedCache doesn’t have the capability to accept objects or to serialize objects. As a result, you need to do this yourself, i.e.: TempData[“PopupMessages”] = JsonConvert.SerializeObject(_popupMessages); Then, of course, after redirecting, you’ll need to deserialize it back into the object you need: TempData[“PopupMessages”] = JsonConvert.DeserializeObject<List<PopupMessage>>(TempData[“PopupMessages”].ToString());

How to get filter to redirect to another action?

RedirectToAction is just a helper method to construct a RedirectToRouteResult(), so what you do is simply create a new RedirectToRouteResult() passing along a RouteValueDictionary() with values for your action. Complete sample based on code from @Domenic in the comment below: public class IsGuestAttribute: ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!Ctx.User.IsGuest) { filterContext.Result … Read more

ASP.NET MVC – How to Preserve ModelState Errors Across RedirectToAction?

I had to solve this problem today myself, and came across this question. Some of the answers are useful (using TempData), but don’t really answer the question at hand. The best advice I found was on this blog post: http://www.jefclaes.be/2012/06/persisting-model-state-when-using-prg.html Basically, use TempData to save and restore the ModelState object. However, it’s a lot cleaner … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)