错误请求MVC HttpPost

时间:2018-01-10 18:28:43

标签: asp.net-mvc oauth-2.0

我有以下cshtml文件。

   @model Models.AuthorizeUser
   @{
   ViewBag.Title = "Authorize";
   Layout = "~/Views/Shared/_Layout.cshtml";
 }

<div class="container">
    <div class="card card-container">
        <img class="profile-img-card" src="~/Content/images/rblogo_reverse-pms348_000.gif" />
        <p>&nbsp;</p>
        <form method="POST">
        <p>Hello, @Model.Name</p>
        <p>A third party application want to do the following on your behalf:</p>
        <ul>

            @foreach (var scope in Model.Scopes)
            {

                <li>@scope.ScopeDescription</li>
            }
        </ul>
            <div class ="row">
                <div class="col-md-4">
                    <button class="btn btn-block btn-primary btn-signin" name="submit" type="submit" value="authorize">Grant</button>
                </div>
                <div class="col-md-8">
                    <button class="btn btn-block btn-primary btn-signin btn-small-text" name="submit" type="submit" value="logout">Sign in as different user</button>
                </div>
            </div>
        </form>
    </div>
</div>

我的控制器文件如下:

public class OAuthController : Controller
{

    [HttpGet]
    public ActionResult Authorize()
    {
        logger.Trace("Authorize method entered");
        AuthorizeUser authorizeUser;
               ......
        return View(authorizeUser);
    }


    [HttpPost]
    public ActionResult Authorize(AuthorizeUser authorizeUser, string submit)
    {
        logger.Trace("Authorize with object");
        if (Response.StatusCode != 200)
        {
            logger.Trace("status code " + Response.StatusCode);
            logger.Trace("status description " + Response.StatusDescription);
            return View("AuthorizeError");
        }
          ..............
    }

显示表单时,信息显示正确。单击“授予”按钮后,我得到了Response.StatusCode == 400. authorizeUser和submit都为null。我期待StatuCode == 200,其值为authrizeUser并提交。

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用Html.BeginForm()

您可以使用<form method="POST">

而不是Html.BeginForm("Action", "Controller")