I have the following problem:
I have a form in the site / bin (currently local The running webserver) that is using a SQL database is created using the link ADO.net and the controller has been started in the following manner:
DBModelEntities _entities; _entities = new DB Model Entity (); // This part is in the controller's creator
Next, I use this database to fill Html.DropDownList () in my database. This is done in two steps. In the controller side we have a constructor:
see data ["education level"] = this. Gate All the education level ();
Another helpful method:
Public Selection List GetAllEducationLevels () {List & lt; Education Level & gt; LstEducationLevels = _entities.EducationLevels.ToList (); Select Lists Slit = New Selection List (LSE Education Level, "ID", "Name"); Returning wrist; }
In the view I have the following:
& lt;% use (HTML.BeginForm ()) {%> & Lt; Fieldset & gt; & Lt; Story & gt; Fields & lt; / Narrative & gt; & Lt ;! - Various text fields here - & gt; & Lt; P & gt; & Lt; Label = "EducationLevels" & gt; Labels for education: & lt; / Label & gt; & Lt ;! - & lt;% = Html.DropDownList (Selection List as "Education Attributes", see Data ["Education Specials"])%> - & gt; & Lt;% = Html.DropDownList ("Education Level", "..select option ..")%> & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "create" / & gt; & Lt; / P & gt; & Lt; / Fieldset & gt; & Lt;%}% & gt;
Now, the form is presented correctly when I browse the page. I can choose etc. But when I was selected I would have to use that value to upload my new model to the database. This is where it is wrong. To do this in my controller, I have the following code:
// post: / create a banner / [AcceptVerbs (HttpVerbs.Post)] Create a public action form (Formalication form) Set the rest of the information, which is automatically set to empty RICK = new vacuum (); //vacatureToAdd.EducationLevels = form ["EducationLevels"]; // Desiarialize (Include white list!) TryUpdateModel (vacateToAdd); // Validate (string.isnelloracty) modelstate. Adold Models ("title", "title is required!"); If (String.IsNullOrEmpty (vacitableToAdd.Content)) ModelState.AddModelError ("Content", "Content Required!"); Update // variables, which are not set form empty. Do this. Time Created = Date Time.Now; // Just created VacationToAdd.UpdatedAt = DateTime.Now; // Just created, then still modified, VacationToAdd.ViewCount = 0; // We have just created it, so there is no vacant vacantToAdd.ID = GetGuid (); // Generate Unique Identifier {// TODO: Add the logging logic here. ADTOVICTURE (emptyAdded); _entities.SaveChanges (); Return to // entry page if successful return redirection projection ("index"); } Hold (exception e) {see return (); }} #endregion
returns this error:
I have found many topics on this but everyone says that you You can retrieve it by using:
vacateToAdd.EducationLevels = form ["EducationLevels"];
However this gives me a string because I am using ASP.N. I'm new because I think I'm not forgetting to select the object to go back and not the string. Maybe it's the value selected in that part where I highlight my selection but I did not know how to set it correctly, of course I can also complete a syndetrack.
Sidenot: I am currently thinking like a different model.
Any help is appreciated.
You can not return anything to normal & gt; SELECT & gt; The tag provided by the HTMLproductionalist () method, but can only be returned to string variables. The education case will be sent to the server in your ID. To rebuild this object by ID, you must define and use another custom assistant method.
Comments
Post a Comment