2016-11-09 20 views
0

我想添加一行到天藍色的表存儲。這是我第一次與這個工作,所以我跟着一個MS教程,不幸的是他們使用控制檯應用程序,而不是MVC,所以我不得不湊合一點,基本上,當[httpPost]添加到我的AddRow方法我得到一個HTTP 404錯誤「在 '/' Application.The資源服務器錯誤無法找到「不能找到方法:使用MVC的httppost將行添加到天藍色表存儲

代碼(裏面的HomeController):

[HttpPost] 
     public ActionResult AddRow() 
     { 
      ViewBag.Message = "Your application description page."; 

      try 
      { 
       CloudStorageAccount cloudStorageAcc = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); 

       CloudTableClient cloudTableClient = cloudStorageAcc.CreateCloudTableClient(); 

       CloudTable table = cloudTableClient.GetTableReference("Users"); 
       table.CreateIfNotExists(); 

       Insert inserter1 = new Insert("Bob", "Contoso"); 
       inserter1.UserName = "Bobbie"; 

       TableOperation insertOperation = TableOperation.Insert(inserter1); 

       table.Execute(insertOperation); 
      } 
      catch 
      { 
       return View(); 
      } 

      return View(); 
     } 

我嘗試mysite.azurewebsites.net/Home/AddRow訪問此

回答

0

Whe我們在瀏覽器中發出請求,默認的HttpMethod是HttpGet。它與函數中定義的HttpMethod(Httppost)不匹配。所以,它會返回上面的錯誤。我們通常使用post方法來登錄表單數據,然後我們可以在視圖頁面中定義httpMethod。

@using (Html.BeginForm("AddRow", "Home", FormMethod.Post)) 
{ 
    // data or logic 
} 

我們也可以使用代碼或工具(postman,fidder)來調用具有已定義的HttpMethod的函數。

看來你設置相同的值到[partitionkeyrowkey]對於每個HTTP請求。如果是這樣的話,它可以在第一時間正常工作。因爲[分區鍵rowkey]是tableEntity(記錄)的唯一值。更多細節請參考document

相關問題