MVC <form action =“@ Href”

时间:2015-04-25 12:51:10

标签: asp.net-mvc asp.net-mvc-5

=“”

我正在做本教程https://www.youtube.com/watch?v=WwmUFTWEh6Y,我遇到了问题为什么@Href不起作用。

@Href我的目标应该指向Update ActionResult中的PostsController,但它不起作用,我也没有看到任何问题。我有一个PostsController,你可以在图片中看到,我在public ActionResult Update中明显有一个PostsController。 为什么会说path not found

在本教程结束时我可能没有留下任何头发了!

<form action="@Href

修改 在图片中,我强调了两件事,但我有点想到了另一件事。

更新:

   public class PostsController : Controller
{   

//UPDATE takes (id, title, body, datetime, tags)
public ActionResult Update(int? id, string title, string body, DateTime dateTime, string tags)
{ .......
}

1 个答案:

答案 0 :(得分:1)

您应该使用@Url.Action("Update", "Posts"),它更容易使用。查看重载方法here的完整列表,然后选择符合您需求的方法。

作为表单的替代方法,您可以使用@Html.BeginForm()。来自here的使用示例:

@using (Html.BeginForm())
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
相关问题