2016-05-05 198 views
0

我遇到了這個錯誤,而使用Url.Action是在「/」應用ASP.net MVC 5Asp.Net MVC Url.Action給404資源沒有找到錯誤

服務器錯誤。 找不到資源。 描述:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。 請求的網址:/ Home/AddPhoto

這裏是視圖的相關部分。下面url.action調用是失敗的一個:@ Url.Action( 「AddPhoto」, 「家」)

</div> 
     @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
     { 
      <div class="col-md-8"> 
       <textarea class="search-query span2 text-center" rows="13" style="width: 2200px; height: 50px;" id="searchText" name="searchText" placeholder="What is on your mind?" type="text" value="What is on your mind? "></textarea> 
       <br /> 
       <a href="#" id="addphoto" onclick="window.location.href='@Url.Action("AddPhoto", "Home")'"> 

        <span rel="tooltip" title="Add photo"><i class="fa fa-camera"></i></span> 
       </a> 
       <br /> 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <input type="reset" value="Cancel" name="Command" style="text-align:right" />&nbsp; &nbsp;<input type="submit" name="Command" value="Post" style="text-align:right" /> 
       <br /> 
       <br /> 

在我HomeController.cs文件,我確實有這個方法:

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

和實際的視圖文件,並在瀏覽/家庭存在

Screen grab of views/home directory

我因此不理解的原因WH我正在打404錯誤。有人能幫我出來嗎?

+1

當你使用瀏覽器URL進入到/ home/AddPhoto,是頁面送達? –

+1

嘗試直接在瀏覽器位置輸入網址並檢查 - http:// localhost:portno/home/AddPhoto是否可訪問? –

+0

@Ashish Kaluskar,試試這個:去行動,onclick查看比選擇「去查看」,比在你的行動頂部添加這個:[HttpPost] – praguan

回答

0

你的情況下的AddPhoto動作必須是[HttpPost]。它應該是[HttpGet]。刪除[HttpPost]。只有GET才能從瀏覽器地址欄中運行。

0

這裏,我們去: 試試這個:

<a href="#" id="addphoto" onclick="window.location.href='../Home/AddPhoto'"> 

<a href="~/Home/AddPhoto" id="addphoto">` 

希望它幫助;)

相關問題