1 Replies - 5555 Views - Last Post: 27 December 2009 - 04:29 PM

#1 coden4fun   User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • member icon

Reputation: 28
  • View blog
  • Posts: 696
  • Joined: 27-February 09

ASP.Net MVC I can edit records using my datamodel but I can't crea

Post icon  Posted 27 December 2009 - 11:37 AM

I am creating a CMS and frontsite web application at the sametime using the ASP.Net MVC framework and MSSQL. I have created an ADO.Net EntityFramework model of one of my database tables in my CMS database entitled Company (since it will host as all Page data in the Company navigation.)

I have created a Details page that will host as the main content for the individuals and a secure Create and Edit template where you can edit the records in the datamodel. The following below is the code.

//Get: //ContentManager/Create
		public ActionResult Create()
		{
			return View();
		}

		//Post: //ContentManager/Create
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Create([Bind(Exclude = "id")] Company companyToCreate)
		{
			try
			{
				_companyEntities.AddToCompany(companyToCreate);
				_companyEntities.SaveChanges();
				return RedirectToAction("CompanyIndex");
			}
			catch(Exception e)
			{
				ViewData["ErrorMessage"] = e.Message.ToString();
				return View();
			}
		}

		//Get:  //ContentManager/EditCompany/id
		public ActionResult EditCompany(int Id)
		{
			var companyToEdit = (from c in _companyEntities.Company
								 where c.id == Id
								 select c).FirstOrDefault();

			return View(companyToEdit);
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult EditCompany(Company companyToEdit)
		{
			try
			{
				var originalCompany = (from c in _companyEntities.Company
									   where c.id == companyToEdit.id
									   select c).FirstOrDefault();

				_companyEntities.ApplyPropertyChanges(originalCompany.EntityKey.EntitySetName, companyToEdit);
				_companyEntities.SaveChanges();
				return RedirectToAction("CompanyIndex");
			}
			catch(Exception e)
			{ 
				//get the ErrorMessage for trouble shooting.
				ViewData["ErrorMessage"] = e.Message.ToString();
				return View();
			}
		}



for the following Error Message that I made a small error message log for the Create template, since I wasn't able to get the following template to create new records and store them in the database
 catch(Exception e)
			{ 
				//get the ErrorMessage for trouble shooting.
				ViewData["ErrorMessage"] = e.Message.ToString();
				return View();
			}




I get the following Error on the template after I try to make a single record with or without a proper ID
An error occurred while updating the entries. See the InnerException for details.



I've made sure that I use debug feature in Visual Studios, which has to configure some stuff in the web.config file, but I can't find any message of InnerException, and C# doesn't recognize it as a generic Exception, so I can't make a log file out of it.

If anyone can please help me with this peculiar anomily I would greatly appreicate it.

Here have been my thoughts on troubleshooting thus far.

If I can't create a record because I can't access the database then I shouldn't be able to view records, or edit them, but I can so that's not the solution.
I'm Creating the records incorrectly in C# (Possible, but I followed a guide thoroughly in the ASP.Net MVC Unleashed)
Something about using a database that's already on the server constantly connecting to it, but then why can I edit the records and they update in real-time?
Create a repository and see if I can create a record using the repository (Which is want I'll be in the middle of soon enough)

please help... please help...

This post has been edited by coden4fun: 27 December 2009 - 11:44 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ASP.Net MVC I can edit records using my datamodel but I can't crea

#2 coden4fun   User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • member icon

Reputation: 28
  • View blog
  • Posts: 696
  • Joined: 27-February 09

Re: ASP.Net MVC I can edit records using my datamodel but I can't crea

Posted 27 December 2009 - 04:29 PM

Ive solved the problem. I was creating a security restraint having the databases hosted on the server and trying to run it through debug on my localmachine
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1