Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
create button code:

<br />
<br />
public ActionResult Create()<br />
        {<br />
            return View();<br />
        }<br />
<br />
        // POST: authors/Create<br />
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for <br />
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.<br />
        [HttpPost]<br />
        [ValidateAntiForgeryToken]<br />
        public ActionResult Create([Bind(Include = "au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] author author)<br />
        {<br />
            if (ModelState.IsValid)<br />
            {<br />
                db.authors.Add(author);<br />
                db.SaveChanges();<br />
                return RedirectToAction("Index");<br />
            }<br />
<br />
            return View(author);<br />
        }<br />
<br />


Delete Button code:

<br />
<br />
public ActionResult Delete(string id)<br />
        {<br />
            if (id == null)<br />
            {<br />
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);<br />
            }<br />
            author author = db.authors.Find(id);<br />
            if (author == null)<br />
            {<br />
                return HttpNotFound();<br />
            }<br />
            return View(author);<br />
        }<br />
<br />
        // POST: authors/Delete/5<br />
        [HttpPost, ActionName("Delete")]<br />
        [ValidateAntiForgeryToken]<br />
        public ActionResult DeleteConfirmed(string id)<br />
        {<br />
            author author = db.authors.Find(id);<br />
            db.authors.Remove(author);<br />
            db.SaveChanges();<br />
            return RedirectToAction("Index");<br />
        }<br />
<br />



same error will be raise in create and delete methods that error location is
db.save changes raise a error.
error like as "Db update Exception was handle by user code"

pls help me,

thank u
Posted

1 solution

I think you are using EntityFramework, so please make sure that the connection string is available in the web.config file. When you are adding the entity framework it will asks for you to add the sensitive data into the project or not. I think you would have select no. Try this and let me know.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900