2011-08-05 53 views
5

在登錄時,使用登錄。錯誤:沒有找到'xx'或其主人的視圖或沒有任何視圖引擎支持搜索的位置...在登錄?

用戶:管理員 密碼:XXX

我可以正常登錄。

當您嘗試:

用戶:tavaresdemelo.adv.br 密碼:顯示XX

錯誤:

The view 'tavaresdemelo.adv.br' or ITS master was not found or the view engine supports the searched locations. The Following Were searched locations: ~/Views/account/tavaresdemelo.adv.br.aspx ~ /Views/account/tavaresdemelo.adv.br.ascx ~/Views/Shared/ tavaresdemelo.adv.br.aspx ~/Views/Shared/ tavaresdemelo.adv.br.ascx ~/Views/account/ tavaresdemelo.adv.br.cshtml ~/Views/account/ tavaresdemelo.adv.br.vbhtml ~/Views/Shared/ tavaresdemelo.adv.br.cshtml ~/Views/Shared/ tavaresdemelo.adv.br.vbhtml

賬戶控制器

public ActionResult LogOn() 
{ 
    return View(); 
} 

[HttpPost] 
public ActionResult LogOn(string userName, string password, string returnUrl) 
{ 
    if (ModelState.IsValid) 
    { 
     if (Membership.ValidateUser(userName, password)) 
     { 
      FormsAuthentication.SetAuthCookie(userName, false); 
      if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") 
       && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) 
       return Redirect(returnUrl); 
      return RedirectToAction("Index", "Home"); 
     } 
     ModelState.AddModelError("", "Usuário ou senha estão inválidos"); 
    } 

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

public ActionResult LogOff() 
{ 
    FormsAuthentication.SignOut(); 
    return RedirectToAction("Index", "Home"); 
} 

查看登錄

@model string 
@{ 
    ViewBag.Title = "Login"; 
} 

<div id="login"> 
    <h2>@ViewBag.Title</h2> 
    @Html.ValidationSummary(true, "Erro ao tentar efetuar o login.") 
    @using (Html.BeginForm()) 
    { 
     <fieldset class="login"> 
      <legend>Entre com seu usuário e senha</legend> 
      <div class="inline"> 
       @Html.Label("userName", "Usuário: ") 
       @Html.TextBox("userName", Html.Encode(Model)) 
       @Html.ValidationMessage("userName") 
      </div> 

      <div class="inline"> 
       @Html.Label("password", "Senha: ") 
       @Html.Password("password") 
       @Html.ValidationMessage("password") 
      </div> 

      <div class="form-buttons"> 
       <input type="submit" class="button" value="Login" title="Login" /> 
      </div> 
     </fieldset> 
    } 
</div> 

回答

9

此行

return View(userName); 

告訴加載一個視圖名爲userName的框架(或在這種情況下tavaresdemelo.adv.br)。這就是爲什麼你所得到的錯誤,它無法找到一個名爲tavaresdemelo.adv.br.aspx的觀點,等等。我覺得正在試圖做的是

return View(); 

什麼
return View("logon"); 

或任何您試圖重新加載視圖的名稱是。

我希望有幫助!

1

對於此錯誤的其他實例,return View("logon")不適用於我。 我發現return RedirectToAction("View", "Controller")確實解決了這個問題。

相關問題