У меня есть простое приложение MVC3, для которого я хочу получить некоторые сведения о конфигурации из службы, разрешить пользователю редактировать и сохранять конфигурацию.
Если в процессе сохранения обнаружены какие-либо ошибки, они должны быть возвращены и сообщены пользователю.
Проблема заключается в том, что не удается вызвать конфигурацию, содержащую ошибки, исохраненные в данный момент значения просто отображаются заново.
Пошаговое выполнение кода, при обнаружении ошибок он должен перенаправить на себя, используя переданный объект конфигурации, но это не так, и он использует метод без параметров.
Кто-нибудь может увидеть, где я иду не так?
Ниже приведены два вызываемых метода контроллера:
//
// 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();
}
}