Thursday, 15 July 2010

asp.net mvc - MVC Updatemodel and Linq-To-Sql creates new entity instead of updating -


I have a survey form with the following data hierarchy

survey - & lt; Survey Question - & lt; Survey Q & A option

I use the update model to update the survey unit in my saved method which works fine for surveys and surveys, even though survey QuestionOptions updates appear when I Update all variables in the debugger check but I receive a new survey after calling the SubmitChanges QuestionOption records Door is

HTML

  & lt;% = HTML. Textbox ("Survey id", Model.Id)%> & Lt;% = Html.TextBox ("Survey.SurveyName", Model SurveyName)%> & Lt;% = Html.TextBox ("survey. Survey question [0] .Id", Model.Id)% & gt; & Lt;% = Html.TextBox ("survey. Survey question [0]. Question", model question)% & gt; & Lt;% = Html.TextBox ("Survey Survey Question [0]. Survey Q & A Options [0] .Id", Model.Id)% & gt; & Lt;% = Html.TextBox ("Survey Survey Question [0]. Survey Q & A Options [0]. Options", Model Options)% & gt; [AcceptVerbs (HttpVerbs.Post)] Public Action Result Service (Int. ID, ILIT & Lt; ChannelForm & gt; Channel Forms, Form Collection FC) {Survey Update Rider = New Survey ( ); // If this is an existing survey, record the record from the database to update (id! = 0) {updateSurvey = surveynRepository.GetSingle (Convert.ToInt32 (ID)); } {// updateSurvey and all child elements UpdateModel (Update Survey, "Survey"); SurveyRepository.Save (); See Return (); } Hold {return see ();}}  

Any help is appreciated

  survey update rider; If (id == 0) {updateSurvey = new survey (); } Other {updateSurvey = Survey Repository. Get SINGLE (convert toInt32 (ID)); } Try {{etetc  
}

No comments:

Post a Comment