서비스에서 일부 구성 세부 정보를 검색하고 사용자가 구성을 편집하고 저장할 수있게 해주는 간단한 MVC3 응용 프로그램이 있습니다.RedirectToAction이 예상대로 작동하지 않습니다.
저장 프로세스 중에 오류가 발견되면이를 반환하고 사용자에게 다시보고해야합니다.
문제는 오류가 포함 된 구성이 호출되지 않고 현재 저장된 값이 다시 표시된다는 것입니다.
오류가 감지되면 전달 된 설정 개체를 사용하여 자체로 리디렉션해야하지만 매개 변수가없는 메서드는 사용하지 않습니다.
어디서 잘못 볼 수 있습니까? 다음은
가 호출되고있는 두 개의 컨트롤러 방법은 다음과 같습니다 리디렉션 때이 같은 복잡한 객체를 전달할 수 없습니다//
// GET: /Settings/Edit/
public ActionResult Edit()
{
SettingsViewModel config = null;
// Set up a channel factory to use the webHTTPBinding
using (WebChannelFactory<IChangeService> serviceChannel =
new WebChannelFactory<IChangeService>(new Uri(baseServiceUrl)))
{
// Retrieve the current configuration from the service for editing
IChangeService channel = serviceChannel.CreateChannel();
config = channel.GetSysConfig();
}
ViewBag.Message = "Service Configuration";
return View(config);
}
//
// POST: /Settings/Edit/
[HttpPost]
public ActionResult Edit(SettingsViewModel config)
{
try
{
if (ModelState.IsValid)
{
// Set up a channel factory to use the webHTTPBinding
using (WebChannelFactory<IChangeService> serviceChannel = new WebChannelFactory<IChangeService>(new Uri(baseServiceUrl)))
{
IChangeService channel = serviceChannel.CreateChannel();
config = channel.SetSysConfig(config);
// Check for any errors returned by the service
if (config.ConfigErrors != null && config.ConfigErrors.Count > 0)
{
// Force the redisplay of the page displaying the errors at the top
return RedirectToAction("Edit", config);
}
}
}
return RedirectToAction("Index", config);
}
catch
{
return View();
}
}
도움을 주셔서 감사합니다 (다시; o). 너는 나를 많이 도와 줬어. 복잡한 객체를 전달하는 다른 방법이 있습니까? SettingsViewModel에 30 개 이상의 매개 변수가 있습니다. – TeamWild
@TeamWild, 임시 저장소 위치에 콜드를 저장하고 고유 ID를 얻은 다음 리디렉션 할 때이 고유 ID를 액션에 전달하여 원래 객체를 다시 가져올 수 있습니다. TempData는 한 가지 방법이지만 개인적으로 Session에 의존하기 때문에 나는 그것을 좋아하지 않습니다. 아마 내 데이터 저장소에 임시로 저장할 것입니다. –
다른 세션에서 구성을 사용하려고 시도하면 변경 사항이 무시되므로 세션 ID를 사용하면 문제가없는 것으로 판단됩니다. 감사. – TeamWild