asp.net NET MVC -我不知道为什么我的POST操作没有被命中

l2osamch  于 6个月前  发布在  .NET
关注(0)|答案(2)|浏览(61)

我已经有几年没有使用ASP.NET MVC了,所以我有点生疏了。我不知道我错过了什么,所以当我提交表单时,我的POST Action不会被击中。这是我的观点:

<form id="unsubscribe-form" method="post" action="Communication/Unsubscribe">
     <div class="col-sm-12 col-md-9 mtl">
         <button type="submit" id="btnSubmit" class="no-underline btn btn-orange btn-block">Yes, I'm Sure</button>
     </div>
</form>

字符串
这是我的行动:

[Route("Communication/Unsubscribe")]
[AnyAccessType]
[HttpPost]
public ActionResult Unsubscribe(UnsubscribeViewModel model)


有什么明显的我错过了为什么这个行动不会被击中?

pdkcd3nj

pdkcd3nj1#

看看这个问题Here和这个帖子Here
应该看起来像这样。如果有疑问,请尝试用 Postman 敲击您的控制器,看看会发生什么。希望这对您有帮助

@model Form_Post_MVC.Models.PersonModel

@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th colspan="2" align="center">Person Details</th>
            </tr>
            <tr>
                <td>PersonId: </td>
                <td>
                    @Html.TextBoxFor(m => m.PersonId)
                </td>
            </tr>
            <tr>
                <td>Name: </td>
                <td>
                    @Html.TextBoxFor(m => m.Name)
                </td>
            </tr>
            <tr>
                <td>Gender: </td>
                <td>
                    @Html.DropDownListFor(m => m.Gender, new List<SelectListItem>
                   { new SelectListItem{Text="Male", Value="M"},
                     new SelectListItem{Text="Female", Value="F"}}, "Please select")
                </td>
            </tr>
            <tr>
                <td>City: </td>
                <td>
                    @Html.TextBoxFor(m => m.City)
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Submit"/></td>
            </tr>
        </table>
    }
</body>
</html>

字符串

eqzww0vc

eqzww0vc2#

确定你的行动路线

[Route("~/Communication/Unsubscribe")]
public ActionResult Unsubscribe(UnsubscribeViewModel model)

字符串
并形成

@model UnsubscribeViewModel
.....

 @using (Html.BeginForm("Unsubscribe", "Communication", FormMethod.Post))
{

....
}

相关问题