When Passing a DateTime Parameter to RedirectToAction (Asp.Net MVC2) either by passing DateTime or by passing a date: "13/4/2000"
return RedirectToAction("index", "ControllerName", new { mydate = DTHelper.PrintDate(myVM.someobject.someobjectDateTime) });
The parameter passed with this representation - which the controller can't resolve:
http://localhost:6105/ControllerName?mydate=19%2F6%2F2011
how can I make it pass as original (it works when I build the url myself):
(this will not work b/c %2F....)
RedirectToAction will return a http 302 response to the browser and then browser will make GET request to specified action. Show activity on this post. Ideally I would use RedirectToRoute for Action Links/Images and RedirectToAction in Controller's Action to redirect to another Controller's Action .
Use this: return RedirectToAction("LogIn", "Account", new { area = "" }); This will redirect to the LogIn action in the Account controller in the "global" area.
Try using the following format when passing dates around: yyyy-MM-dd
:
var date = myVM.someobject.someobjectDateTime.ToString("yyyy-MM-dd");
return RedirectToAction("index", "ControllerName", new { mydate = date });
Now inside Index you should be able to get the correct date:
public ActionResult Index(DateTime mydate)
{
...
}
and if you wanted a time component use the following format: yyyy-MM-dd HH:mm:ss
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With