On my MVC webpage I have an ActionLink like this:
@Html.ActionLink("Create", "Index", "Project")
The view is Index.cshtml and the controller is "Project".
When clicked on this link I want it to go to the controller and do actionResult for Create. But when I click it it wants to go to /projects/index and nothing happens because the actionresult method for create isn't called. It calls the actionresult for Index. So nothing actually happens, the page simply refreshes.
If I change the Actionlink to:
@Html.ActionLink("Create", "Create", "Project")
it tries to go to "/projects/create" but can't find it because it doesn't exist.
My ActionResult code looks like this:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "projectName,projectType")] Project project)
{
if (ModelState.IsValid)
{
db.Project.Add(project);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(project);
}
How do I solve this?