POST重定向C#后无法找到页面

时间:2018-03-22 16:46:19

标签: c# post razor

我转到View,通过POST提交数据,但重定向无法找到Controller方法。我在这做错了什么?提交表格后我得到:

404 error: cannot find page. URL is:  http://localhost:52008/InternalController/UpdateCardFormPost

来自InternalController.cs的片段:

public ActionResult UpdateCardFormView()
{
    var CardToUpdate = new CardView();
    return View(CardToUpdate);//return implementation of Cards.cshtml with the empty model that was passed to it
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UpdateCardFormPost(CardView c)
{
    CardModelIO.WriteCard(c);//@TODO: IMPLEMENT

    return View("CardDetailView", c);
}

UpdateCardFormView.cshtml(包含我提交的表单的视图):

@using LeanKit.API.Client.Library.TransferObjects
@model CardView

<!DOCTYPE html>
<html>
<!--Form used to change a card
    STARTING DISPLAY called by in Internal/UpdateCardFormView
    ENDING DISPLAY (post) called by UpdateCardForm in InternalController a specified below-->
<head>
</head>
<body>
    @Html.BeginForm("UpdateCardFormPost", "InternalController", FormMethod.Post)
    @Html.TextBoxFor(c => c.AssignedUserName);
    <input type="submit" value="Submit Changes" />

</body>
</html> 

继承了CardDetailView.cshtml(我应该重定向到的视图):

@using LeanKit.API.Client.Library.TransferObjects
@model IEnumerable<CardView>
<!--used for displaying an individual card in detail view
    referenced in UpdateCardFormPost() method of Internal controller-->

<!DOCTYPE html>

<html>
<head>
</head>
<body>
    CardView j = Model;
    <p>j.AssignedUserId</p>
</body>
</html> 

3 个答案:

答案 0 :(得分:1)

您已将控制器名称指定为InternalController,但它可能只称为“内部”。

尝试更改

@Html.BeginForm("UpdateCardFormPost", "InternalController", FormMethod.Post)

@Html.BeginForm("UpdateCardFormPost", "Internal", FormMethod.Post)

答案 1 :(得分:0)

您缺少结束表单标记

你应该像

那样做
using (@Html.BeginForm("UpdateCardFormPost", "InternalController", FormMethod.Post))
{
   ...
}

答案 2 :(得分:0)

@using(Html.BeginForm()) {

@Html.TextBoxFor(c => c.AssignedUserName);
<input type="submit" value="Submit Changes" />

}