1

我有一个带有 ActionResult 的控制器,我在初始构建之后添加了一个名为 SubAlertModal 的控制器

     [HttpPost]
public ActionResult SubAlertModal(int alertid)
{

    var SubAlerts = from sa in db.csSubAlerts
                    where sa.AlertID == alertid
                    select sa;

  //  csAlert cssubalert = db.csAlerts.Find(alertid);


 //   return View();

   return Request.IsAjaxRequest() ? PartialView(SubAlerts) :   

       PartialView(SubAlerts);

}

在 Index.cshtml 页面上,我添加了一个 HTML.ActionLink,看起来像下面这样

@foreach (var item in Model) {
<tr>
    <td>
        @Html.ActionLink("Sub_Alert", "SubAlertModal", new { id = item.AlertID }, new { 
     @class = "ModalOpener" })
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Routes)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Issue)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Detour)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateEntered)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.FullName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.SendEmail)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id = item.AlertID }, new {   
    @class="ModalOpener" }) |
        @Html.ActionLink("Details", "Details", new {id = item.AlertID }) |
        @Html.ActionLink("Delete", "Delete", new { id = item.AlertID})
    </td>
</tr>
}

一个问题是第一个。当我单击列表中的 Sub_Alert 时,它给了我一个 404 错误。网址是正确的。控制器是否与视图不匹配。这是我现在要在模式窗口或任何窗口中加载的视图@model IEnumerable

@{
ViewBag.Title = "SubAlerts";
 }

     <h2>SubAlert</h2>
<div id="SubAlertModal" title="Sub Alert for the Alert">
This is a test modal
and it appears to be working !!

<table>
<tr>

    <th>
        @Html.DisplayNameFor(model => model.Issue)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Detour)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.DateEntered)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.EnteredBy)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.SendEmail)
    </th>
    <th></th>
 </tr>

  @foreach (var item in Model) {
 <tr>

    <td>
        @Html.DisplayFor(modelItem => item.Issue)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Detour)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateEntered)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.FullName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.SendEmail)
    </td>

</tr>
}

</table>



</div>

谢谢

4

1 回答 1

1

如果您通过链接访问操作方法,那么 HTTP 动词是 GET,而不是帖子。

您的操作方法设置为仅响应 POST。

只需将其删除[HttpPost]或更改为[HttpGet]

于 2013-08-28T18:39:14.130 回答