Search code examples
asp.net

the form is to move to another view once the form submit button is clicked


In my HTML: i created the following form:`

    <form action="@Url.Action("CheckRequestsLists", "Home")" method="post" >
        <figure>
            <img class="img-thumbnail" style="width:110px; height:80px;"
                 src="~/Content/Images/CheckLists.png" />
            <figcaption class="fig">
                <input style="border:none"
               type="submit" value="View All Requests" />
            </figcaption>
        </figure>

        <input hidden style="border:unset" type="text" name="Submitted_By"
               value="@Session["user"]" readonly />
    </form>
</div>`
  in controller: I have the following ActionResult [HttpPost]
    [ActionName("ReuestResource")]
    public ActionResult CheckRequestsLists()
    {
       var test = Requestsdbo.Requests.Where(x => x.Submitted_By == "phuuser").ToList();

        return RedirectToAction("CheckRequestsLists", test);
    }

The resource cannot be found. Description: 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. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/CheckRequestsLists


Solution

  • Looks like your ActionName alters the way the action is exposed.

    From your code:

    [ActionName("ReuestResource")]
    public ActionResult CheckRequestsLists()
    

    The action should be now available at /home/ReuestResource rather than /home/CheckRequestsLists.

    Try to reflect that in your Url.Action

    <form action="@Url.Action("ReuestResource", "Home")" method="post">