2012-02-17 47 views
0

當用戶訪問我的主頁並且他們單擊登錄按鈕時,它會彈出包含常規表單的jquery ui對話框。mvc3從視圖重定向和從部分重定向導致http 500錯誤

 @using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @name = "user-login-form", @id = "user-login-form" })) 
     { 
      <fieldset style="margin: 10px 0 0 0;"> 
       <label for="name"> 
        Username</label> 
       <input type="text" name="UserName" id="username" class="text ui-widget-content ui-corner-all" /> 
       <label for="password"> 
        Password</label> 
       <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" /> 
      </fieldset> 
     } 

此表單存在於作爲主控制器上索引視圖一部分的部分視圖中。正如你可以看到它發佈到帳戶控制器中的登錄操作。以下是該行動。

[HttpPost] 
    public ActionResult LogOn(LogOnModel model, string returnUrl) // rename either the model or the view name field to match. 
    { 
     if (ModelState.IsValid) 
     { 
      if (MembershipService.ValidateUser(model.UserName, model.Password)) 
      { 
       AuthenticationService.SignIn(model.UserName, model.RememberMe); 

       if (Url.IsLocalUrl(returnUrl)) 
       { 
        return Redirect(returnUrl); 
       } 

       if (MembershipService.IsUserInRole(model.UserName, "ServiceProvider")) 
       { 
        return RedirectToAction("Index", "ServiceProvider"); 
       } 

       return RedirectToAction("Index", "Project"); 
      } 

      ModelState.AddModelError("", "The user name or password provided is incorrect."); 
     } 

     // If we got this far, something failed, redisplay form 
     return View(model); 
    } 

正如你可以看到,如果該模型不是有效它發送你到登錄視圖(不是部分),這是賬戶控制器的一部分。

問題是......無論我以任何方式填寫部分或常規視圖中的表格,我最終都會在/ Account/LogOn頁面發生500錯誤。我已經完成了一百次,我似乎無法弄清楚發生了什麼問題。數據是正確的。用戶名和密碼經過驗證,但我從來沒有真正實現過Project控制器上的Index操作。

在項目控制器中的索引操作存在,它是所有返回查看()。 Index.cshtml文件確實存在。即使我刪除所有模型並儘可能簡化網頁,我仍然會遇到同樣的問題。保持在/帳戶/登錄頁面有500錯誤,而不是/ Project/Index。

我已經做了一些搜索,沒有找到從阿賈克斯等重定向...和東西說你不應該從一個局部的,但即使從它不工作的常規視圖重定向一些東西。不知道它可能是一個IIS問題或什麼?絕對願意嘗試任何事情......一直在這方面掙扎了兩天。

感謝,

回答

0

1)500服務器錯誤意味着腳本已經拋出一個錯誤,這是不是一個破碎的鏈接像404 error.So使用「友好HTTP錯誤」,這會給你一個更全面的描述的錯誤,所以你可以調試腳本。 2)嘗試使用剃刀語法MVC 3象下面或使用視圖強類型。 3)可能是你的密碼屬性不對(它的密碼不是密碼)。

@using(Html.BeginForm()){

<div> 
    <fieldset> 
     <legend>Account Information</legend> 
 <div class="editor-label"> 
      @Html.LabelFor(m => m.UserName) 
     </div> 
     <div class="editor-field"> 
      @Html.TextBoxFor(m => m.UserName) 
      @Html.ValidationMessageFor(m => m.UserName) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(m => m.Password) 
     </div> 
     <div class="editor-field"> 
      @Html.PasswordFor(m => m.Password) 
      @Html.ValidationMessageFor(m => m.Password) 
     </div> 


     <p> 
      <input type="submit" value="Log On" /> 
     </p> 
    </fieldset> 
</div> 

}

+0

你是正確的...這是隱藏在目標視圖中的編譯錯誤。我試圖通過說@ html.Partial(「...」)顯然不存在... – 2012-02-17 20:14:15