c# - Form Post Not working While Submission -
whenever try post form following error:
an error occurred while getting provider information database. can caused entity framework using incorrect connection string. check inner exceptions details , ensure connection string correct.
public class contactcontroller : controller { [httpget] public actionresult index() { return view(new contactmessage()); } [httppost] public actionresult index(contactmessage post) { if(modelstate.isvalid) { //save 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); } }
you have fix connection. incorrect connection string may have different causes. try connect database server explorer in visual studio select database , press f4 (properties). can see correct connection string there. put in connection string in web.config.
Comments
Post a Comment