2017-02-24 5 views
0

MapRouteMVC 5 Routen Post Modell funktioniert nicht

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

Aktion Methode

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

Kontaktformular 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" /> 

} 

Wenn ich meine Form schreiben .. Ich AntiForgeryToken entfernt () und das gleiche Ergebnis getestet.

HTTP-Fehler 404.0 - Nicht gefunden

+0

Wie lautet der Name des Controllers, in dem sich die ContactForm-Aktion befindet? – MartinM

+0

Controller: SiteHomeController Aktion: Kontaktformular. Get Methode funktioniert, aber wenn ich versuche, Post zeigt 404. – Actionsee

+0

Wie posten Sie das Formular? Rufen Sie den Umgang mit der Client-Seite für den Antiforg-Token an? – MartinM

Antwort

0

Ihr Actionname "Contact" aber Sie schreiben

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

Es muss;

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

Und Ihr Routing wie;

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

Und Ihre Aktion wie;

Und entfernen Sie die AntiForgeryToken, wenn Sie Ihre Daten veröffentlichen können Sie später hinzufügen.

+0

Danke, aber ich habe für Englisch geändert. Ich verwende den gleichen Controllernamen und Aktionsnamen. Ich möchte spezielle URL verwenden. Ich weiß, dass es auf Standardroute funktioniert. – Actionsee