NetCore MVC - Jak wypełnić parametry akcji HttpGet z poziomu RedirectToAction?

0

Witam. Posiadam akcję w kontrolerze:

[Authorize]
public async Task<IActionResult> Create(string owner, Guid? roomId, DateTime? reservationDate)

Potrzebuję teraz wywołać tę akcję z poziomu innej akcji. Z tego co udało mi się wyczytać muszę użyć RedirectToAction i wypełnić parametr fragment
Co robię źle?

            catch(Exception e)
            {
                string fragment = "?";
                if(_owner != null)
                {
                    fragment += "owner=" + _owner.FullNameWithEmail;
                    if (_room != null) fragment += "&";
                }
                if (_room != null)
                {
                    fragment += "roomId=" + _room.ID;
                    if (_reservatinDate != DateTime.MinValue) fragment += "&";
                }
                if(_reservatinDate != DateTime.MinValue)
                {
                    fragment += "reservationDate=" + _reservatinDate.ToShortDateString();
                }

                
                return RedirectToAction("Create", "Reservations", null, fragment);
            }

Po wywołaniu akcji Create parametr owner jest równy null, a nie powinien. Jeżeli wpiszę na sztywno w przeglądarkę
/Reservations/Create?owner=awdawd to wypełnia mi poprawnie, więc błąd jest gdzieś przy wypełnianiu RedirectToAction


Próbowałem również tak:

return await Create(
                    (_owner != null) ? _owner.FullNameWithEmail : null, 
                    (_room != null) ? (Guid?)_room.ID : null,
                    (_reservatinDate != DateTime.MinValue) ? (DateTime?)_reservatinDate : null
                    );

W tym przypadku akcja Create dostaje prawidłowe dane, jednak zwracany jest nie ten widok :(

1

Ja bym jak najmniej programował logiki w wyjątkach, ale to bardzo mglista reguła, czasem trzeba.

i odkryłem zupełnie niedawno automatyczne sklejanie z separatorem

List<string> conditions ;
... 
var arr = conditions.ToArray();
var x = String.Join("&",arr);
0

Problem rozwiązany:
W akcji: Verify

return await Create(
                    (_owner != null) ? _owner.FullNameWithEmail : null, 
                    (_room != null) ? (Guid?)_room.ID : null,
                    (_reservatinDate != DateTime.MinValue) ? (DateTime?)_reservatinDate : null
                    );

W akcji Create zmianiełem return View(Model) na return View("Create", Model)

@AnyKtokolwiek a jak potrzebuję odczytać "Exception" to jak wtedy go wysłać? Musze to zrobić w tym miejscu ;D

1 użytkowników online, w tym zalogowanych: 0, gości: 1