Entwickler-Ecke

ASP.NET und Web - RedirectToAction bringt Laufzeitfehler


erfahrener Neuling - Mo 15.07.19 15:30
Titel: RedirectToAction bringt Laufzeitfehler
Hallo Leute,

bei einem Asp-MVC5-Projekt ist mir heute etwas komisches passiert. Und zwar rufe ich aus einer Action heraus eine andere Action per RedirectToAction auf. Funktioniert ja sonst auch.

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
[HttpPost]
public ActionResult Action1(MeinModel model)
{
    ...
    return RedirectToAction(nameof(Action2), "MeinController"new { param1 = model.Value1, param2 = Model.Value2 }); 
}

[HttpPost]
public ActionResult Action2(string param1, int param2)
{
    ...
}
In diesem Fall wird die Action2 gar nicht erreicht. Er lädt eine Weile und bringt dann eine Fehlerseite
errorASP

Hat jemand ne Idee woran es liegen könnte?

MfG.
Julian


Th69 - Mo 15.07.19 15:49

Hast du denn bisher noch kein Fehler-Logging bei dir eingebaut? Dann s. z.B. Errors handling and logging in ASP.NET MVC [http://blog.chudinov.net/errors-handling-and-logging-in-asp-net-mvc/] oder Demystifying ASP.NET MVC 5 Error Pages and Error Logging [https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging].

Da steht ja etwas von einer weiteren Exception - evtl. schau auch mal mit der Ereignisanzeige ("event viewer") nach.


erfahrener Neuling - Mo 15.07.19 16:02

Also Fehlerlogging gab es hier noch nicht.
Ich habe den Fehler selbst gefunden: Anscheinend kann man nicht ohne weiteres auf eine Post-Methode Redirecten [https://stackoverflow.com/a/129361].

Nimmt man das HttpPost-Attribut bei Action2 weg, funktioniert es.

C#-Quelltext
1:
2:
3:
4:
5:
[HttpGet]
public ActionResult Action2(string param1, int param2)
{
    ...
}