2017-02-24 32 views
0

MapRouteMVC 5つの路線ポストモデルでは、(私はAntiForgeryTokenを削除...

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

アクションメソッド

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

お問い合わせフォームコード

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

} 

私は自分のフォームをポストに動作しません。 )、同じ結果をテストした。

HTTPエラー404.0から

+0

ContactFormアクションがあるコントローラの名前は何ですか? – MartinM

+0

コントローラ:SiteHomeControllerアクション:ContactForm。メソッドは動作しますが、投稿を表示しようとすると404が表示されます。 – Actionsee

+0

どのようにフォームを投稿していますか?あなたは偽造防止のトークンのクライアント側を扱っていますか? – MartinM

答えて

0

あなたのActionResult名 "のContactForm" しかし、あなたはそれでなければなりません

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

を投稿が見つかりませんでした。

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

あなたのルーティングは次のとおりです。

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

あなたの行動は次のとおりです。

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

AntiForgeryTokenを削除し、データを投稿して後で追加することができます。

+0

ありがとう、しかし私は英語のために変わった。私は同じコントローラ名とアクション名を使用しています。私は特別なURLを使いたい。私はそれがデフォルトルートで動作することを知っています。 – Actionsee

関連する問題