2012-09-20 84 views
0

我有我的代碼有問題:重定向錯誤asp.net

  • 我會重定向到帶有參數的動作從CSHTML文件
  • 但找不到URL 文件管理CSHTML:

    @{ Layout = "~/Views/Shared/_General.cshtml"; 
    } 
    <table> 
        <tr> 
         <td><label title= "Name " runat="server">Name</label></td> 
         <td><label title= "Email " runat="server">Email</label></td> 
         <td><label title= "Password" runat="server">Password</label></td> 
         <td><label title= "Phone" runat="server">Phone</label></td> 
        </tr> 
    
        @foreach (var marker in @Model) 
        { 
         <tr> 
          <td><label title= "Nom " runat="server" >@marker.ContactName</label>/td> 
          <td><label title= "mail " runat="server">@marker.ContactEmail</label>/td> 
          <td><label title= "mot " runat="server" >@marker.Password</label>/td> 
          <td><label title= "phone " runat="server" >@marker.ContactPhone</label></td> 
          <td><label id="id" style="visibility:hidden">@marker.Identification</label></td> 
          <td>@Html.ActionLink("Edit", "Edit", new { Identification = @marker.Identification }) | @Html.ActionLink("Delete", "Delete", "Administration")</td> 
         </tr> 
        } 
    </table> 
    <p> 
        @Html.ActionLink("Create New", "Create") 
    </p> 
    

我的行爲是這樣的:

[HttpPost] 
public ActionResult Edit(string Identification) 
{ 
    DATA2.User u = c.GetUserById(Identification); 
    return View(u); 
} 

如何更正此代碼?

回答

0

當你看到你的代碼時,第一件事就是打我runat="server"。 ASP.NET MVC中沒有這樣的事情。請從您使用它的每個地方刪除它。

我可以在代碼中看到的一個問題是,您使用[HttpPost]屬性對控制器操作進行了修飾。不要忘記,當你定義一個ActionLink時,它會生成一個錨標籤(<a>),然後它會向服務器發送一個GET請求。如果您使用[HttpPost]屬性來修飾控制器操作,則基本上只會說明此操作只能通過POST HTTP動詞進行調用。如果你想動作要由ActionLink的訪問,您將不得不刪除這個屬性:

public ActionResult Edit(string Identification) 
{ 
    DATA2.User u = c.GetUserById(Identification); 
    return View(u); 
} 

接下來,我想我們必須專注編輯鏈接:

@Html.ActionLink("Edit", "Edit", new { Identification = marker.Identification }) 

你說這找不到編輯操作,對不對?如果是這種情況,那麼你也可以指定控制器動作,也是區域(如果該控制器所在的區域內):如果你想達到控制器的動作沒有被定義

@Html.ActionLink(
    "Edit", 
    "Edit", 
    "SomeContorller", 
    new { Identification = "marker.Identification" }, 
    null 
) 

這是必要的在用於渲染視圖的同一個控制器中。