HTTP错误405.0 - 方法不允许 - 正在使用无效方法(HTTP动词)

时间:2015-01-06 04:24:37

标签: asp.net-mvc razor model-view-controller elasticsearch

我试图从在MVC视图中创建的表单发布但我收到405.0错误。我已将此控制器和视图添加到试图实现ElasticSearchCRUD的现有项目中。我有其他控制器在项目中正常运行。是不是所有需要的控制器中Index方法的HttpPost属性?

以下是相关代码:

查看:

@using (Html.BeginForm("Index", "Search"))
{
@Html.ValidationSummary(true)

<fieldset class="form">
    <legend>CREATE a new document in the search engine</legend>
    <table width="500">
        <tr>
           ....
        <tr>
            <td>
                <br />
                <input type="submit" value="Add" style="width:200px" />
            </td>
            <td></td>
        </tr>
    </table>
</fieldset>

呈现HTML:

<form action="/Search" method="post">    <fieldset class="form">
    <legend>CREATE a new document in the search engine</legend>
    <table width="500">
        <tr>
         ....
        <tr>
            <td>
                <br />
                <input type="submit" value="Add Material" style="width:200px" />
            </td>
            <td></td>
        </tr>
    </table>
</fieldset>

控制器:

[HttpPost]
    public ActionResult Index(MyModel model)
    {
        if (ModelState.IsValid)
        {
            model.DateCreated = DateTime.UtcNow;
            model.Updated = DateTime.UtcNow;
            _searchProvider.AddUpdateEntity(model);

            return Redirect("Search/Index");
        }

        return View("Index", model);
    }

0 个答案:

没有答案