2015-06-20 181 views
0

工作每當我嘗試後我的狀態,我得到以下錯誤:表單提交不提交時

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

public class ContactController : Controller 
{ 
    [HttpGet] 
    public ActionResult Index() 
    { 
     return View(new ContactMessage()); 
    } 

    [HttpPost] 
    public ActionResult Index(ContactMessage post) 
    { 
     if(ModelState.IsValid) 
     { 
      //Save to Database 
      using (var db=new ContactMVC.Data.ContactDatabase()) 
      { 
       post.DateSent = DateTime.Now; 

       db.ContactMessages.Add(post); 
       db.SaveChanges(); 
      } 
      //redirect 
      TempData["ContactMessage"] = post; 
      return RedirectToAction("SucessfulMessage"); 
     } 
     return View(post); 
    } 

    public ActionResult SucessfulMessage() 
    { 
     var message = (ContactMessage)TempData["ContactMessage"]; 
     return View(message); 
    } 
} 
+0

可以向我們展示內部異常嗎? – alisabzevari

+1

您是否檢查連接字符串和內部異常,如錯誤所示? – Zabavsky

+0

@alisabzevari什麼內部異常? –

回答

0

您必須解決您的連接。但錯誤的連接字符串可能有不同的原因。嘗試使用Visual Studio中的Server Explorer連接到數據庫,然後選擇您的數據庫並按F4(屬性)。你可以在那裏看到正確的連接字符串。把它放在你的web.config中的連接字符串中。

+0

謝謝,解決了這個問題 –