RedirectToAction和“对象已移至此处".错误 [英] RedirectToAction and "Object moved to here" error
问题描述
我在MVC 3.0中遇到RedirectToAction的奇怪问题.
I'm having a strange issue with RedirectToAction in MVC 3.0.
这是我的示例ViewModel的代码
Here is the code of 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 is the 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);
}
我的问题是,如果删除AllowHtmlAttribute
并在描述字段中插入纯文本,一切正常,并且保存后得到重定向,但是如果我将AllowHtmlAttribute
放在字段描述中并插入一些HTML文本,保存而不是重定向后,我得到的空白页面只有以下文本:
My problem is, if I remove the AllowHtmlAttribute
and insert plain text in the description field, all is ok and I get my redirect after save, but if I put the AllowHtmlAttribute
on the field description and insert some Html text, after save instead of the redirect I get a blank page with only this text:
Object moved to here.
如果单击此处",则将重定向到正确的URL.
If I click on "here", I'm redirected to the right url.
我缺少明显的东西吗?
推荐答案
它实际上是由httpModule干扰mvc引起的.我遇到了同样的问题,并通过从主要web.config中删除以下内容来解决了该问题.
Its actually cause by a httpModule interfering with mvc. I had same issue and fixed it by removing the following from the main web.config.
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v11.1, Version=11.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
这篇关于RedirectToAction和“对象已移至此处".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!