RedirectToAction error and "Object moved here" error

I am having a weird issue with RedirectToAction in MVC 3.0.

Here is the code for my sample ViewModel

public class EventViewModel
{
  [Required(ErrorMessageResourceType = typeof(Resources.Validations), ErrorMessageResourceName = "Required")]
  public DateTime CreationDate { get; set; }

  [Required(ErrorMessageResourceType = typeof(Resources.Validations), ErrorMessageResourceName = "Required")]
  [AllowHtml] //here is my apparent problem
  public string Description { get; set; }

  [Required(ErrorMessageResourceType = typeof(Resources.Validations), ErrorMessageResourceName = "Required")]
  [Range(0, 5, ErrorMessageResourceType = typeof(Resources.Validations), ErrorMessageResourceName = "RangeValue")]
  public int Rating { get; set; }
  [Required(ErrorMessageResourceType = typeof(Resources.Validations), ErrorMessageResourceName = "Required")]
  public string Title{ get; set; }

  ...other properties...

}

Here are two methods of my controller

public ActionResult Edit(int id)
{
  var entity = eventsRepository.Get(id);
  if (entity == null)
    return RedirectToAction("Index");
  var eventVM = new EventViewModel();
  eventVM.Description = entity.Description;

  ... set the other properties ...

  return View(eventVM);
}

[HttpPost]
public ActionResult Edit(int id, EventViewModel model)
{
  if (ModelState.IsValid)
  {
    try
    {
      var entity = eventsRepository.Get(id);
      if (entity == null)
        return RedirectToAction("Index");
      entity.CreationDate = model.CreationDate;
      entity.Description = model.Description;

      ... set the other properties ...

      eventsRepository.Save(entity);
      return RedirectToAction("Index");
    }
    catch (Exception e)
    {
      ModelState.AddModelError("", "An error occured bla bla bla");
    }
  }

  return View(model);
}

My problem is that if I delete AllowHtmlAttributeand paste plain text in the description field, everything is fine, and I get my redirect after saving, but if I put AllowHtmlAttributein the description of the field and insert some Html text, after saving instead of redirecting I I get a blank page with only this text:

Object moved to here. 

If I click here, I am redirected to the correct URL.

Am I missing something obvious?

+3
source share
3 answers

, httpModule mvc. ​​, web.config .

<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v11.1, Version=11.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
+3

. , , http . , [allowhtml] , , , , .

+3

RedirectToAction HTTP- . , ASP.Net , , , , , RedirectToAction.

, Edit(int id, EventViewModel model), , EventViewModel, "".

Edit(int id, EventViewModel model)

... set the other properties ...

eventsRepository.Save(entity);

var eventVM = new EventViewModel();
eventVM.Description = entity.Description;

... set the other properties ...

return View(eventVM);
0

All Articles