4

我想在點擊部分視圖中調用div。我寫了這個未找到部分視圖'First.cshtml'或沒有視圖引擎支持搜索的位置

@Ajax.ActionLink("Second", "Second", new AjaxOptions() 
{ 
    HttpMethod = "GET", 
    UpdateTargetId = "partials", 
    InsertionMode = InsertionMode.Replace 
}) 

<div id="partials"> 
</div> 

<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script> 
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script> 
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script> 
<script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2/jquery.validate.unobtrusive.min.js" type="text/javascript"></script> 

在我的Index.cshtml。我的控制器看起來是這樣的:

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

     public PartialViewResult Second() 
     { 

      return PartialView("Second.cshtml"); 
     } 

但我的錯誤說我的局部視圖可以在未發現:

~/Views/switchPartial/Second.cshtml.aspx 
~/Views/switchPartial/Second.cshtml.ascx 
~/Views/Shared/Second.cshtml.aspx 
~/Views/Shared/Second.cshtml.ascx 
~/Views/switchPartial/Second.cshtml.cshtml 
~/Views/switchPartial/Second.cshtml.vbhtml 
~/Views/Shared/Second.cshtml.cshtml 
~/Views/Shared/Second.cshtml.vbhtml 

,但我有它在switchPartial文件夾..

如果我會在我的div中寫@Html.Partial("Second")它正確呈現我的部分視圖

我做錯了什麼?

回答

4

不需要在部分名稱的末尾包含文件擴展名。嘗試:

return PartialView("Second"); 

通過不包括文件的擴展名,每個註冊ViewEngines的給予其機會,以解決請求的視圖(在Second.cshtmlSecond.vbhtmlSecond.aspx)。

相關問題