@Html.BeginForm not finding controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hello,

I am developing a custom search plugin.

The view has a simple form on it.

I am getting problems with it not finding the controller.

My controller is called "SiteWideDocumentSearchController"

I have the following action in the controller:


[HttpPost, ActionName("DocumentSearch")]
public ActionResult DocumentSearch(string searchType, string searchValue) {

.....

Return View();
}


In my view the form looks like this:


@using (Html.BeginForm("SiteWideDocumentSearch", "DocumentSearch", FormMethod.Post)) {
  <select name="searchType">
    <option value="SmartWorksId">Smart Works Id</option>
    <option value="DocumentTitle">Document Title</option>
  </select>
  <input type="text" name="searchValue" />
  <input type="submit" value="Search">
}


When I look at the raw html generated for the page the form gets rendered like this:

<form action="/DocumentSearch/SiteWideDocumentSearch" method="post">


The GET action of this controller is reached with the following url..

http://trev.chili-publish.com/Plugins/SiteWideReOrder/DocumentSearch


Can anyone help please?

Thanks
9 years ago
Try with

@using (Html.BeginForm("DocumentSearch","SiteWideDocumentSearch", FormMethod.Post)) {
  <select name="searchType">
    <option value="SmartWorksId">Smart Works Id</option>
    <option value="DocumentTitle">Document Title</option>
  </select>
  <input type="text" name="searchValue" />
  <input type="submit" value="Search">
}
9 years ago
Hi,

As Sohel suggested, your helper method syntax should be Html.BeginForm("action", "controller", FormMethod.Post). Btw, if your action method name is same as the action name (DocumentSearch), it is no need to specify the action name in the attribute, [HttpPost] is enough.

Regards,
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.