2012-09-20 88 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 
) 

这是必要的在用于渲染视图的同一个控制器中。