1
votes

I have a controller with a ActionResult I added after the initial build Named 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);

}

on the Index.cshtml page I add an HTML.ActionLink the looks like the folling

@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>
}

the one inquestion is the first . when i click on the Sub_Alert in the list it gives me a 404 error. the url is correct. is the controller not matching up with the view. this is the view i want to load in a modal window or any window at this point @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>

Thanks

Joe

1
What is your controller name? Home? If it is not Home you need to explicitly put in the controller name. - Sithu
my controller name is AlertController and all my other actions work(Create, Edit, Detaills and Delete) Now I created the new actionresult named SubAlertModal(custom) but it should still wire up. when i click go to controller from the view it goes in vs. - Joe Cook

1 Answers

1
votes

If you are accessing the action method via a link, then the HTTP verb is a GET, not a post.

Your action method is set up to only respond to a POST.

Simply remove [HttpPost] or change it to [HttpGet]