1

MapRoute

routes.MapRoute(
    name: "ContactForm",
    url: "contact-form.html",
    defaults: new { controller = "SiteHome", action = "ContactForm" },
    namespaces: new[] { "Presentation.Controllers" }                
);

Action Method

[AllowAnonymous]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult ContactForm(ContactForm postForm)
{
}

Contact Form Codes

@using (Html.BeginForm("IletisimForm", "SiteAnasayfa", FormMethod.Post, htmlAttributes: new { @class = "" }))
{

     @Html.AntiForgeryToken() 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" })

     @Html.TextBoxFor(model => model.Fullname, new { @class = "w-input easing" })
     @Html.ValidationMessageFor(model => model.Fullname, "", new { @class = "text-danger text-bold" })

     @Html.TextBoxFor(model => model.Telephone, new { @class = "w-input easing")
     @Html.ValidationMessageFor(model => model.Telephone, "", new { @class = "text-danger text-bold" })

     @Html.TextBoxFor(model => model.Email, new { @class = "w-input easing")
     @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger text-bold" })

     @Html.TextAreaFor(model => model.Message, new { @class = "w-input easing" })
     @Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger text-bold" })

     <input type="submit" class="fr w-button easing" value="Send" />

}

When i post my form.. I removed AntiForgeryToken() and tested same result.

HTTP Error 404.0 - Not Found

Actionsee
  • 107
  • 1
  • 11

1 Answers1

0

Your ActionResult name "ContactForm" but you post

@using (Html.BeginForm("IletisimForm", "SiteAnasayfa", FormMethod.Post, htmlAttributes: new { @class = "" }))

It must be;

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, htmlAttributes: new { @class = "" }))

And your routing like;

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

And your action like;

[HttpPost]
public ActionResult ContactForm(ContactForm postForm)
{
}

And remove the AntiForgeryToken, if you post your data you can add later.

Murat Gündeş
  • 852
  • 2
  • 17
  • 31
  • Thanks but i changed for english. I am using same controller name and action name. I want to use special url. I know it works on default route. – Actionsee Feb 24 '17 at 13:35