asp.net mvc - Getting message “Store update, insert, or delete statement affected an unexpected number of rows (0)” ? -
another big problem, here.
i have model:
public class lead { [system.componentmodel.dataannotations.column("le_codlead")] public int leadid {get; set; } [system.componentmodel.dataannotations.column("le_descr1")] [required(errormessage="inserire nome del lead")] [display(name="nominativo lead")] public string name1 {get; set;} [system.componentmodel.dataannotations.column("le_descr2")] [display(name = "nominativo secondario")] public string name2 { get; set; } ... ... ... }
controller (for create method):
[httppost] public actionresult create(lead lead) { if (modelstate.isvalid) { db.leads.add(lead); db.savechanges(); return redirecttoaction("index"); } return view(lead); }
and view:
@model crmarcadia.models.lead @{ viewbag.title = "create"; } <h2>create</h2> <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (html.beginform()) { @html.validationsummary(true, "attenzione! compilare tutti campi obbligatori") <fieldset> <legend>lead</legend> <div class="editor-label"> @html.labelfor(model => model.name1) </div> <div class="editor-field"> @html.editorfor(model => model.name1) @html.validationmessagefor(model => model.name1) </div> <div class="editor-label"> @html.labelfor(model => model.name2) </div> <div class="editor-field"> @html.editorfor(model => model.name2) @html.validationmessagefor(model => model.name2) </div> ... ... ... <p> <input type="submit" value="create" /> </p> </fieldset> }
but when try insert new lead throws exception in post title: entity framework: “store update, insert, or delete statement affected unexpected number of rows (0).” read on web caused id key (leadid, in case) not updating: suggest insert hiddenfor attribute in view id key, , did:
@html.hiddenfor(model => model.leadid)
but 1 @ pressure of create button nothing happens.
does has solution (or workaround ;) ) @ problem, please?
thanks.
do have layer communicate ef ? entity context?
for update scenario:
if using same action create/edit place @html.hiddenfor(model => model.leadid)
- hidden field between blocks @using (html.beginform()) { .... </fieldset> }
.
if not help, @ article msdn - working objects
Comments
Post a Comment