Reputation: 3829
I am working on a sample mvc project in which I am trying to post data to a controller. I have posted sample (see below), but if I add [HttpPost] to method I am getting '404' error.
View:
<% using (Html.BeginForm()) { %>
<%= Html.Telerik().NumericTextBox()
.Name("NumericTextBox")
.Spinners(false)
.EmptyMessage("ID")
%>
<input type="submit" value="Submit" />
<% } %>
Controller:
[HttpPost]
public ActionResult GetDetails(int id)
{
return View();
}
**I also tried,**
[HttpPost]
public ActionResult GetDetails(FormCollection collection)
{
return View();
}
Route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Customer", action = "GetDetails", id = UrlParameter.Optional } // Parameter defaults
);
Upvotes: 0
Views: 2539
Reputation: 102723
You'll want the Name to match the parameter on the controller, so I believe it should be like this:
Html.Telerik().NumericTextBox()
.Name("id")
Notes:
id
route parameter, it's not truly optional unless you make it nullable (ie, int? id
) in the controller action.Upvotes: 2
Reputation: 93424
You should use the second method, but instead of FormsCollection
, use:
GetDetails(int NumericTextBox)
The parameter must be the same name as the input box.
Upvotes: 0