[HttpPost] publicActionResult
Edit_Matrix( Matrix
data ) { if
(ModelState.IsValid ) {
Db.MatrixData.Add( data ); // I know that this is probably not correct but this is NOT the current issue!
( ( EFDbContext)
Db ).SaveChanges(); return
View( "Home"
); } else
return View( data ); }
The problem is that I keep getting this exception:
Exception: System.Web.HttpException (0x80004005): A public action method 'Edit_Matrix' was not found on controller 'My_MSI.Net.Controllers.AdminBackOfficeController'. at System.Web.Mvc.Controller.HandleUnknownAction(String actionName) at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.b__5() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.b__d() at System.Web.Mvc.SecurityUtil.b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Your link site: Creating an EF Data Model did not show how the edit functionalitiy was created or it's possible that it was auto generated and I skipped over that step mainly because I I don't want to auto generate code to delete records which could cause
issues with the database.
A critical step must have been left out. Because when I try to create a new controller set up with the template they used, I get an error:
Unable to retrieve metadata for 'My_MSI.Net.Models.Entities.Matrix'.
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an Exception.
Well, something is wrong with my installation of Visual Studio 2008 then. And I don' have the money to pay Microsoft to fix the problem. So all I can do is rely on the good people here to help me understand what needs to be changed.
eric2820
Contributor
2777 Points
1161 Posts
Trying to edit an existing record with MVC 3
Mar 01, 2012 07:40 AM|LINK
I have a MVC 3 project that needs to edit an existing record in the database (SQL Server 2008 R2).
The first View simply prompts for a record number, and call a second controller method to actually load the record.
The problem is that I keep getting an exception when the second method gets called:
[HttpGet]
public ActionResult EditMatrix()
{
EditRecord data = new EditRecord();
return View( data );
}
[HttpPost]
public ActionResult EditMatrix( EditRecord data )
{
Matrix _data = new Matrix();
if (data.RecordNubmer != 0 )
{
_data = Db.MatrixData.First( m => m.id == data.RecordNumber );
}
return View( "Edit_Matrix", _data );
}
[HttpPost]
public ActionResult Edit_Matrix( Matrix data )
{
if (ModelState.IsValid )
{
Db.MatrixData.Add( data ); // I know that this is probably not correct but this is NOT the current issue!
( ( EFDbContext) Db ).SaveChanges();
return View( "Home" );
}
else
return View( data );
}
The problem is that I keep getting this exception:
Exception: System.Web.HttpException (0x80004005): A public action method 'Edit_Matrix' was not found on controller 'My_MSI.Net.Controllers.AdminBackOfficeController'. at System.Web.Mvc.Controller.HandleUnknownAction(String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.b__5() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.b__0() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.b__d() at System.Web.Mvc.SecurityUtil.b__0(Action f) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 09:52 AM|LINK
did you re-compile the project?
eric2820
Contributor
2777 Points
1161 Posts
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 09:54 AM|LINK
Okay, I've solved the Exception issue with this controller code:
[HttpGet]
public ActionResult EditMatrix()
{
EditRecord data = new EditRecord();
return View( data );
}
[HttpPost]
public ActionResult EditMatrix( EditRecord data )
{
Matrix _data = new Matrix();
if (data.RecordNumber != 0 )
{
_data = Db.MatrixData.First( m => m.id == data.RecordNumber );
}
return View( "Edit_Matrix", _data );
}
public ActionResult Edit_Matrix( Matrix data )
{
if (ModelState.IsValid && data.id != 0 )
{
Db.MatrixData.Add( data );
( (EFDbContext) Db ).SaveChanges();
return View( "Home" );
}
else
return View( data );
}
And this is the EditMatrix View:
@model My_MSI.Net.Models.Entities.
EditRecord
@{
ViewBag.Title = "Admin | Back Office | Edit Matrix";
Layout = "~/Views/Shared/_BackOffice_Layout.cshtml";
}
<h2>Admin | Back Office | Edit Matrix</h2>
@Html.BeginForm()
{
@Html.Label( "Matrix Id to Edit: " )
@Html.TextBox( "id", Model.RecordNumber )
<input name="Submit" id="Submit", type="submit" runat="server" />
}
Now the only problem is that the data.id is always 0 even though I entered a different value!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 10:00 AM|LINK
PLease open a new thread for this. It involves views and others...
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 10:26 PM|LINK
Creating an EF Data Model
eric2820
Contributor
2777 Points
1161 Posts
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 11:20 PM|LINK
Your link site: Creating an EF Data Model did not show how the edit functionalitiy was created or it's possible that it was auto generated and I skipped over that step mainly because I I don't want to auto generate code to delete records which could cause issues with the database.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 11:23 PM|LINK
Go through the tutorial, it explains edit/update/delete. It doesn't matter if it's code-first or DB first.
Fiddler tool is also your friend.
eric2820
Contributor
2777 Points
1161 Posts
Re: Trying to edit an existing record with MVC 3
Mar 01, 2012 11:47 PM|LINK
A critical step must have been left out. Because when I try to create a new controller set up with the template they used, I get an error:
Unable to retrieve metadata for 'My_MSI.Net.Models.Entities.Matrix'.
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an Exception.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Trying to edit an existing record with MVC 3
Mar 02, 2012 12:20 AM|LINK
A step left out of what? We have thousands of customers who have successfully completed that tutorial.
eric2820
Contributor
2777 Points
1161 Posts
Re: Trying to edit an existing record with MVC 3
Mar 02, 2012 09:34 AM|LINK
Well, something is wrong with my installation of Visual Studio 2008 then. And I don' have the money to pay Microsoft to fix the problem. So all I can do is rely on the good people here to help me understand what needs to be changed.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.