Hello guys, totally new to MVC and I've built a small simple application with the help of a book I'm reading. But, needless to say it, I run into some problems. Let me run through what I did and what the problem is (by the way, I'm not so sure how easy it will be to show you the code, I will probably add everything to pastebin...funny they say the MVC application are easier to test...um...not so sure about that).
ANyway, my project is called Storage_test and it is nothing else than a form that allows users to input some data in a database and then retrieve them on the same page.
Now, let me say that while I appreciate this can be done in more effective ways, as said I've just started and found this method fairly easy, so I rather fix this than finding a better one.
So, first of all, I created a database, named Storage_test.sdf and the table in it Storage_test_records (the book suggested to do that with SQL Server Compact and so I did), here is the screenshot: http://s10.postimg.org/n8em2mw3t/Storage_test_records.png
Then I proceeded to create a model class StorageRecord.cs which essentially is a representation of the storage record which will go in the database, here http://pastebin.com/FT1s40wk
Then a StorageRecordContext.cs that contains the DbContex info to use the Entity Framework info (Which the book made me install as an add on to Visual studio 2012), here http://pastebin.com/xqaH6XqE
And a controller called StorageController.css here http://pastebin.com/YYBhiQYN that has 2 versions of Create method (one that simply returns a view and the other one that upload the content to the database) and an Index one.
Needless to say, I've created the relative Views: Create - which contains the form - http://pastebin.com/Adgs6Jvb and Index that takes care of displaying the data stored on the database http://pastebin.com/VXuLUvRx
So, here is the thing: When I navigate to Storage/Create I have the form to fill in, and when I submit it, the page returns the Index method which is supposed to show me what I have submitted to the database. It all works, as you can see from here http://s22.postimg.org/ahj6n9i5d/index.png, but if I go into my application and check the table in the database, it is empty. At first, I thought, well you know I need to refresh it, so did that and even closed the app down and resubmitted again, but the table is still empty. Clearly the data submitted is going somewhere, but where the heck? It is supposed to be in that table on that database, and yet, it's not. Surely I'm doing something stupid, considering that I have first created an example in the book about a very similar program which works fine and has no issues with the database table at all, but this one I built has, and I'm going insane trying to understand why. In my StorageRecordContext.css I'm passing the name of the database to the base class (DbContext
) with this line public StorageRecordContext() : base("Storage_test") { }
, so shouldn't that be enough to guarantee that the data inserted go in fact in that database?
Any help, is as usual, is much appreciated
thanks