redirecttoaction

Asp.Net core Tempdata and redirecttoaction not working

自闭症网瘾萝莉.ら 提交于 2021-02-20 05:50:24
问题 I have a method in my basecontroller class that adds data to tempdata to display pop-up messages. protected void AddPopupMessage(SeverityLevels severityLevel, string title, string message) { var newPopupMessage = new PopupMessage() { SeverityLevel = severityLevel, Title = title, Message = message }; _popupMessages.Add(newPopupMessage); TempData["PopupMessages"] = _popupMessages; } If the action returns a view, this works fine. If the action is calling a redirectotoaction I get the following

How do you link to an action that takes an array as a parameter (RedirectToAction and/or ActionLink)?

爷,独闯天下 提交于 2021-01-02 08:11:14
问题 I have an action defined like so: public ActionResult Foo(int[] bar) { ... } Url's like this will work as expected: .../Controller/Foo?bar=1&bar=3&bar=5 I have another action that does some work and then redirects to the Foo action above for some computed values of bar . Is there a simple way of specifying the route values with RedirectToAction or ActionLink so that the url's get generated like the above example? These don't seem to work: return RedirectToAction("Foo", new { bar = new[] { 1,

keep viewdata on RedirectToAction

孤人 提交于 2020-05-24 11:48:32
问题 [AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateUser([Bind(Exclude = "Id")] User user) { ... db.SubmitChanges(); ViewData["info"] = "The account has been created."; return RedirectToAction("Index", "Admin"); } This doesnt keep the "info" text in the viewdata after the redirectToAction. How would I get around this issue in the most elegant way? My current idea is to put the stuff from the Index controlleraction in a [NonAction] and call that method from both the Index action and in the

How to pass class via RedirectToAction

筅森魡賤 提交于 2020-02-04 15:50:13
问题 I have the following code: public ActionResult Index() { AdminPreRegUploadModel model = new AdminPreRegUploadModel() { SuccessCount = successAddedCount, FailureCount = failedAddedCount, AddedFailure = addedFailure, AddedSuccess = addedSuccess }; return RedirectToAction("PreRegExceUpload", new { model = model }); } public ActionResult PreRegExceUpload(AdminPreRegUploadModel model) { return View(model); } but model is null when I breakpoint on PreRegExcelUpload. Why? 回答1: Instead of using the

ASP MVC ActionFilterAttribute OnActionExecuting not fired

对着背影说爱祢 提交于 2020-01-02 17:12:38
问题 I have 2 controllers Home with public class HomeController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { // do some irrelevant stuff base.OnActionExecuting(filterContext); } public ActionResult Index() { return View(); } } and Service with public ActionResult Confirm() { return RedirectToAction("Index", "Home");} And one ActionFilterAttribute with OnActionExecuting method public class InvitationModeAttribute : ActionFilterAttribute { public

How to get filter to redirect to another action?

烂漫一生 提交于 2019-12-29 03:11:20
问题 RedirectToAction is protected, and we can use it only inside actions. But if I want to redirect in a filter? public class IsGuestAttribute: ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!Ctx.User.IsGuest) filterContext.Result = (filterContext.Controller as Controller) .RedirectToAction("Index", "Home"); } } 回答1: RedirectToAction is just a helper method to construct a RedirectToRouteResult() , so what you do is simply create a new

The value for a object inside a viewmodel lost on redirect to action in asp.net mvc 2.0?

。_饼干妹妹 提交于 2019-12-25 04:39:08
问题 I have a view model - public class MyViewModel { public int id{get;set;}; Public SomeClass obj{get;set;}; } public class SomeClass { public int phone{get;set;}; public int zip{get;set;}; } So on my controller when I post back MyViewModel it has all the values for all the fields...but when I do return RedirectoAction("SomeAction",vm);//where vm->MyViewModel object that has all values... it loses the values for SomeClass object?...can anyone please help me out 回答1: The second argument to

RedirectToAction throws 400 error in IE10

Deadly 提交于 2019-12-18 07:09:09
问题 I have an ASP.Net MVC3 site using RedirectToAction like so: return RedirectToAction("Index", interstitialController, new { userName = model.logInInfo.UserName, redirectString = redirectUrl, authToken = login.authenticationToken, reason = login.reason, status = login.status, provider = login.provider }); For some reason this is causing IE10 to generate this as a request: https://site.com/(F(7vkS9Als2GF4acdwa9JNTwHsOkeFIsGcdMGU-FIT0X1IC3UwpkeZrPvTp1WmCbC7aY890yhpaeS4dadGjjUrym9Z_UOHYUUezRjD

setting query string in redirecttoaction in asp.net mvc

三世轮回 提交于 2019-12-18 04:16:20
问题 I have to do a redirecttoaction call in asp.net mvc view with varying params, extracted from the referrer page of the view (the status of a grid). I have (in an hidden field) the content of the query string (sometimes empty, sometimes with 2 parameters and so on), so I have problems to create the route values array. Are there some helpers, that help me to convert a query string a route values array? Something like: string querystring ="sortdir=asc&pag=5"; return RedirectToAction( "Index",

Redirect to Action in another controller

拈花ヽ惹草 提交于 2019-12-17 15:12:12
问题 I have two controllers, both called AccountController . One of them, lets call it Controller A , is in an Area called Admin and the other, lets call it Controller B , is not in any Area (I guess that means it's in the default Area ?). Controller B has an action method called Login . I have an action method in Controller A , which has this line return RedirectToAction("LogIn", "Account"); The problem is that I get a 404 when this line gets executed because an attempt is made to redirect to a