Strange behavior in an MVC4 action post. I have created a custom route as this:
routes.MapRoute(
name: "Projects",
url: "{company}/{project}/{id}/{action}",
defaults: new { controller = "Projects", action = "Index" },
constraints: new { id = @"\d+" }
When my Edit page uses
<form action="/COMPANY/Projects/Edit/1" method="post">
(where Projects is name of the controller) the update works fine, however when I use
@using (Html.BeginForm())
which translates to
<form action="/COMPANY/PROJECT/1/Edit" method="post">
COMPANY and PROJECT are both dynamic values and could look like this
<form action="/sith-co/death-star/1/Edit" method="post">
the model is null. The Request.Form data is the same either way, it does hit the correct action. The only difference is the action string and that the model is null
Controller
[HttpPost]
public ActionResult Edit(project project)
{
Edit
Thanks to JOBG’s answer I was able to make a discovery when I had a similar issue with another controller. For some reason the {project} parameter in the route was getting bound instead of the model. By changing the parameter name to {projectName} all was well in the land of MVC again.
Try changing the name of the variable to something else like: