2010-08-30 107 views
0

我的故事是:我有几个单独的视图中的表单,发布描述信息进行编辑。而且每个描述都属于不同的地方。因此,我还在我的表单中发送refTypeId信息以决定哪些描述属于哪里。到目前为止确定。但我想返回编辑描述视图,在编辑描述之后发送表单。所以我需要知道我的EditDescription操作中编辑的表单来自哪里。我的EditDescription操作方法如下代码:Asp.Net Mvc重定向问题?

[Authorize] 
    [HttpPost] 
    public ActionResult EditDescription(string descriptionToEdit, int refTypeId) 
    { 
     var entity = _entities.Descriptions.Where(e => e.Id == refTypeId).Select(e => e).FirstOrDefault(); 
     entity.Description = descriptionToEdit; 
     _entities.SaveChanges(); 
     var Description = _entities.Descriptions.Where(e => e.Id == refTypeId).Select(e => e).FirstOrDefault(); 


     ViewData["Description"] = Description.Description; 
     TempData["Message"]="Description has been saved"; 
     return (?);// i need to know which view that form was sent from 
    } 

回答

1

发送另一个名为ReturnUrl的参数,并在成功时重定向到它。

+0

用这种方式我需要为我所有的无数形式做到这一点。它应该是其他更好的解决方案。也许在HttpContext类中。 – beratuslu 2010-08-30 13:37:03

+0

您可以随时重定向到Request.UrlReferrer,但每次都可能不正确。例如,如果您通过登录页面重定向。 – Sruly 2010-08-30 13:48:05