MVC :: 2 NerdDinner - Data No Longer Saves After Adding ViewModel
Sep 3, 2010
I am creating the NerdDinner application via the Professional ASP.NET MVC 2 book, and once I got to the ViewModel part (pages 88-91), I noticed none of my data was saving any longer. I discovered several errors and areas of confusion in these pages of the book, which I will list now.
Page 88: When it says to add the DinnerFormViewModel class, it doesn't say what folder to add it to. On page 89, the Inherits example (NerdDinner.Controllers.DinnerFormViewModel) implies it was added to the Controllers folder, but if that were so, the code on page 88 would need to use Models.Dinner instead of just Dinner. No big deal; just put it in Models and change the Inherit statement on page 89 to use NerdDinner.Models.DinnerFormViewModel.
Page 89: At the bottom of the page is some wrong code. Since the properties of Dinner are now one level deeper, all references to m.Title, m.Country, etc, need to be m.Dinner.Title, m.Dinner.Country, etc. The statements above the code are also incorrect ("Notice... we are not changing the names of the input elements... the form elements will still be named...") -- the form elements will actually change from "Title", "Country", etc to "Dinner_Title", "Dinner_Country", etc.
Page 90 (Code Snippet 1-53): This was the one that broke the data saving. Now that the form elements have prefixes, the TryUpdateModel(dinner) needs to pass a prefix, like TryUpdateModel(dinner, "Dinner"). This will append "Dinner_" to the element names so that they can be found on the form.
DbClick the code behind file of NerdDiner.edmx,It reads "This code was generated from a template." on the top comment lines. I generate my own .edmx file automatically with VS2010, just found that the .designer.cs file didnt contains Objectset,Methods as nerddinner does IDK which template hanselman used to generate this .edmx files，dont tell me he wrote it all by himself! Shoud .edmx and its code behind file be generated automaticlly without hard-coding?
I am trying to create a view that would contain a set of fields that tie to an AgencyAddress object, an add button, and under those fields, a list of AgencyAddress that would show addresses that were added. My view works, and the fields are properly bound, however I can't seem to get the list to maintain previously added addresses.
What happens, is that every time the Add button is pressed, the List is re-created (or VS yells at me to create a new instance) and only contains one record. I'm sure I'm missing something simple, but I can't figure out how to pass the list back and forth and be able to add to it. Two weeks on my own is where I draw the line! My ViewModel:
I have a login page inside of a master page. On the left-hand side of the master page in side a navigation menu, there is a search box with a button that is set to be the default submit button via code when text has been entered into the search text box.
ABOVE the search box is a ASP:LoginStatus control that when the user clicks "Login" it takes you to a login.aspx page which contains a ASP:Login control inside the same master page. Without setting the LoginImageUrl and LogoutImageUrl properties of the ASP:LoginStatus, the login/logout appears as text. And the enter button works when a user enters text into the search box (submits info to search service and takes user to search results) OR if the user enters their user name and password into the Login control and hits enter (logs in and redirects user based upon role). Everything works fine. Once I set the loginImageUrl and LogoutImageUrl properties of the ASP:LoginStatus though, the enter key no longer submits anything. It will just postback the page.
I'm guessing that adding an image to those properties cause the loginstatus to take the default behavior of a button. How do I prevent it from breaking the behavior of the enter key on everything else?
I have a strange situation.An ASP.NET button click event causes an object in memory to be updated. The object was loaded from NHibernate via Refresh() during Page_Load, but at no time during the entire page life cycle is Commit() or Flush() called.At some point after the page's OnUnload step, the object and any changes made to it are automatically persisted to the database. I cannot see when or where or why this occurs.
I have an ASP.NET website where we are generating pdf's and web pages using crystal reports. One of the requirements we have is for in the pdf's to have a map of NY state with markers on it that are placed based on GIS Coordinates. For the web page we can do this easily with google maps. if there are any third party map generating solutions that can do this? We currently use map info and google maps, but I dont think either are capable of doing this?
I am wondering if it is possible (for as little money as possible) to create a web page that when a user clicks the submit button saves a file as a PDF. it is going to be used as a purchase order creator on a webpage. I have seen a few tutorials around but they seem to use software that requires purchasing a license.
I am having an issue with the DataSet saving the name of the Database that the table or query is ran from in the .xsd inside the DbObjectName even though it is being called from the connectionstring in the web.config file. I have the following line in the connectionstring setting the initial catalog to the DB name:
the line adds the DB name (dbName_Sandbox.dbo.MySQLScript) automatically, how do I stop this and only have dbo.MySQLScript?
Example of someone else having same issue, but they just did a mass find replace, I don't want to do this every time I have to create a DataSet then deploy to the production server.
I have uploaded the nerddinner sample to "www.aaa.com/test/nerd". When a mouse is on menu tab such as "Find a host" then the link is shown at the bottom of Internet explorer as "www.aaa.com/test/nerd/Dinner" with the contoller name "Dinner". When the mouse is on the main logo which is on top and left, the link shown as "www.aaa.com". So it direct me to "www.aaa.com" instead of "www.aaa.com/test/nerd"
When can I change it? I have tried change the "start url" from the application property, but it did not work.
As I am working thru the NerdDinner MVC example. I found that after implementing step 6 that edits to a dinner were no longer saved. After some investigation I found that I needed to add the ValueProvider to the UpdateModel function call in Edit (HttpPost) example. My updated code is below.
If I write the following code, teh gridview will no longer show the data
gridview.DataSource = null; gridview.Databound.
My question is , I want to make the same thing with a user control that contain a gridview. when I use the user control in an aspx page, I am able to populate it with data, but when I try to make this code, the Datasource does not show, instead, I see .DV. So I tried this code but then , I do not see DataSource property instead I see DV (DataView), when I put .DV = null, I get an error message that the object is not in existed. any idea how to clear the user control gridview from its data.
I have problem when I am working on the NerdDinner tutorial. If I create local database (in the project local) then it is working OK, but if I added connection with the database already existed in the SQL EXPRESS 2005 (using Data Connections -> Add Connection; from the Server Explored in the VS 2008) then I got GPF. Does anyone know how to use the database for server instead of local project?
I am trying to pass a view model of mine, which has multiple list in it, to my view. Then in my view i need to edit the different list. Then on my post i need to save the edits. Although, when i pass my viewmodel back to my post, it is empty! Can somebody explain what i am doing wrong? Controller
point out an example or tutorial online that shows where data validation is done in the viewmodelas against the model? i saw a number of posts where that method is recommended..i dont really agree with it but i would like to see how it would work out..
I started a website based on the NerdDinner source code, everything worked fine (more or less) but whenever I post an event, it ends up on the exact same coordinates on the map regardless of the address (Somewhere in the Gulf of Guinea!)
No idea what to do: I didn't alter the map code at all!
I am using a model but as I want to have clean views I use the viewmodel approach which is like a downsized model which I map in my controller actions before sending to the view or getting it back in a HttpPost attributed action.
My question is: where to put the data annotation attributes. On the viewmodel classes or on the model? If I get it clearly the viewmodel annotations are used for the client side generation of validation right?
Do does that mean I have to put data annotations everywhere on both model and viewmodel?
I am still at the elementary stages of Linq To Sql and Entities usage. I started practicing MVC developement by following the NerdDinner tutorial here at asp.net, and I back myself up with fully developed NerdDinner sample (1.0 -- still on VS2008). I am also at the first half of the NerdDinner tutorial (I think -- maybe I'm further along) - so far I have gotten up to the Delete View. In the fully developed sample I noted that it uses ascx file (which I guess I will find out if the tutorial also will use ascx files down the road). My sample app, which I am developing from the tutorial, seems to work OK so far. My issue is that I am not clear how the Delete mechanism works. In the DinnerRepository.cs I have this code (from the tutorial):
It looks like a dinner object is being passed to these mechanisms and the delete occurs based on a row ID value. But what if I wanted to delete multiple rows - say where ID between 15 and 20 - how to go about this? I was looking for a Delete statement but am not finding it either in what I have developed so far from my tutorial sample or from the fully developed sample. How can I control Deletes in MVC?
I'm trying to use the Nerddinner as a model to built my own project. I'm using the repository method but I cannot fiqure out why the Edit does not save to the database. I tested in the Nerddinner and it failed to save as well. Is this not functional in Nerdinner or could it be due to me using VS 2010 express?
I also started using MVC3 so I thought that could be the problem. I did some testing and was able to get my Edit to update to the database if I have the controller access the database instead of the repository.