Ajax.ActionLink使用POST方法找不到Controller / Action

时间:2015-01-25 18:46:41

标签: ajax asp.net-mvc-4 post actionlink

我很难尝试使用Ajax方法POST一个ActionLink。我已经看过类似的问题,并尝试了所有这些。在这里寻求帮助。请注意,控制器/操作作为GET正常工作,但必须成为不在URL中显示SSN的帖子。

My Controller/Action (CustomersController/Select)

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Select(string id = null) //Customer name has just been selected:
    {
       .
       .
       .
    }

我的.cshtml代码:

    <td>
        @Html.AntiForgeryToken()
        @Ajax.ActionLink("Select", "Select", "Customers", new { id=item.SSN }, new AjaxOptions {HttpMethod = "POST"})
    </td>

呈现的HTML代码:

    <td>
        <input name="__RequestVerificationToken" type="hidden" value="9HJVwEHdFvjvJhDl2BJpByi-4x1qOJ7Yb4lTbJYsWNsf1izFejebW4F44kZv76lXKqht38upDyk3VtkYFYb9MubGLVEw2C6jSTwq23pgGLc1" />
        <a data-ajax="true" data-ajax-method="POST" href="/Customers/Select/444-87-0987">Select</a>
    </td>

点击HTML链接时出错:

        <b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is spelled correctly.
        <br><br>

        <b> Requested URL: </b>/Customers/Select/113-54-6545<br><br>

我确保在.cshtml文件中引用了正确的脚本。 (jquery.unobtrusive-ajax.js)

感谢您的帮助。

0 个答案:

没有答案