2017-02-04 14 views
1

問題の答えが見つかりませんでしたので、この質問をもう一度お願いします。 MVC5とEntity FrameworkでVisual Studioを使用してフォームを送信しています。私の問題は、フォームにアクセスしようとすると、「リソースを見つけることができません」というエラーが表示されます(フランス語で画面に表示されます。 は、ここに私のアーキテクチャです:ここでリソースMVCエンティティフレームワークを見つけることができません

MonLivredor /コントローラ/ HomeController.cs

MonLivredor /ビュー/ホーム/ Formulaire.cshtml

は、私は、フォームからの投稿データを取得するために、コントローラでの使用方法であり、 :

[HttpPost] 
    public ActionResult Formulaire() 
    { 

     String nom = Request.Form["nom"]; 
     String mail = Request.Form["mail"]; 
     String message = Request.Form["message"]; 

     Commentaire com = new Commentaire(nom, mail, message); 
     context.Liste.Add(com); 
     context.SaveChanges(); 

     return View(context); 

    } 

そして最後に、私はVS 2015で手動で起動しよう私のフォーム:

<h2>Formulaire</h2> 
<form method="post" action="/Home/Formulaire"> 
    <h2>Nom</h2> 
    <input type="text" id="nom" name="nom"/> 
    <h2>Mail</h2> 
    <input type="text" id="mail" name="mail"/> 
    <h2>Message</h2> 
    <input type="text" id="message" name="message"/> 
</form> 

だけで助けることができる場合には、ここで私のglobal.asax.csは、任意の変更なしである:私は、冗長対象のため申し訳ありません

using System; 
using System.Collections.Generic; 
using System.ComponentModel.DataAnnotations; 
using System.ComponentModel.DataAnnotations.Schema; 
using System.Linq; 
using System.Web; 

namespace MonLivredor.Models 
{ 
    public class Commentaire 
    { 
     [Key] 
     public int ID { get; set; } 
     public String Nom { get; set; } 
     public String Mail { get; set; } 
     public String Message { get; set; } 
     public DateTime CreateDate { get; set; } 

     public Commentaire(String nom, String mail, String message) 
     { 
      CreateDate = DateTime.Now; 
      this.Nom = nom; 
      this.Mail = mail; 
      this.Message = message; 
     } 

     public Commentaire() 
     { 
     } 


    } 
} 

namespace MonLivredor 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 
      GlobalConfiguration.Configure(WebApiConfig.Register); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
      BundleConfig.RegisterBundles(BundleTable.Bundles); 
     } 
    } 
} 

はここでモデルCommentaire.csです動作するものは見つかりませんでした。ルーティングを変更しようとしましたが、どちらの方法も役に立たないようです。そのようなフォームであなたの助け:)あなたがタグ名を使用する必要があります

+0

_Formulaire.cshtm l_ビュー? – Steve

+0

それはCommentaire.csと呼ばれています。私はそれを追加します –

答えて

0

= "" のための おかげで、:

[HttpPost] 
    public ActionResult Formulaire(Commentaire com) 
    { 

     context.Liste.Add(com); 
     context.SaveChanges(); 

     return View(context); 

    } 

<h2>Formulaire</h2> 
<form method="post" action="/Home/Formulaire"> 
    <h2>Nom</h2> 
    <input type="text" id="nom" name="nom"/> 
    <h2>Mail</h2> 
    <input type="text" id="mail" name="mail"/> 
    <h2>Message</h2> 
    <input type="text" id="message" name="message"/> 
</form> 

とあなたの方法のためのより良い方法は、ModelBinderを使用しています

とあなたのフォームのmvcフレームワーク補助メソッド:

<h2>Formulaire</h2> 
    @using (Html.Beginform("Formulaire","Home")) 
{ 
     <h2>Nom</h2> 
     @Html.Editor("nom") 
     <h2>Mail</h2> 
     @Html.Editor("mail") 
     <h2>Message</h2> 
     @Html.Editor("message") 

} 
+1

ああ良い点、また忘れた '/' ... –

関連する問題