2012-02-13 59 views
0

以下代碼重定向到具有錨點和工作方式的視圖。不過,我需要發送模型狀態進行驗證,我不確定如何在使用重定向時執行此操作。我想設置模型錯誤來填充驗證摘要。MVC ASP.NET - 重定向到模型狀態的錨點

[HttpPost] 
    public ActionResult Send(QuoteModel model, string CatchAll) 
    { 
     try 
     { 

      if (ModelState.IsValid) 
      { 

      } 
      else 
      { 
       ModelState.AddModelError(string.Empty, "There is something wrong with Foo."); 
       return Redirect(Url.RouteUrl(new { controller = "Home", action = "Index"}) + "#quote"); 
      } 
     } 
     catch 
     { 
      return View(); 
     } 
    } 

回答

1

我認爲你不能做這種方式,嘗試添加額外的參數爲您的操作,以確定是否發生錯誤

return Redirect(Url.RouteUrl(new { controller = "Home", action = "Index"}) + "?modelerror=true" + "#quote"); 

,並在你的行動檢查此網址參數。