繁体   English   中英

重定向错误asp.net

[英]redirection error asp.net

我的代码有问题:

  • 我将使用cshtml文件中的参数重定向到操作
  • 但找不到网址admin 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);
}

如何更正此代码?

查找您的代码时,令我runat="server"的第一件事是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
)

如果您要达到的控制器操作未在用于渲染视图的同一控制器中定义,则这是必需的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM