我在使用MVC 3.0中的RedirectToAction時遇到了一個奇怪的問題。RedirectToAction和「對象移到這裏」錯誤
這裏是我的樣品視圖模型的代碼
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...
}
這裏是我的控制器的兩種方法
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文本,在保存而不是重定向後,我得到一個只有這個文本的空白頁面:
Object moved to here.
如果我點擊「這裏」,我被重定向到正確的網址。
我錯過了一些明顯的東西嗎?
謝謝你解決了這個問題。我沒有注意到,在新的示例項目中,我沒有在httpmodule中包含devexpress的調用。 – Iridio 2012-02-08 09:05:46