TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
albert albert
NA
524
0
Error in the Edit
Jul 8 2012 4:15 PM
Hi Everybody,
I have and mvc3 application:
ActivityController:
[code]
public ActionResult Edit(int id)
{
Activity activity = db.Activities.Find(id);
PopulateProjectsDropDownList(activity.ProjectID);
activity = db.Activities
.Include(i => i.Employee)
.Where(i => i.ActivityID == id)
.Single();
PopulateAssignedEmployeeData(activity);
return View(activity);
}//end method
[HttpPost]
public ActionResult Edit(int? id, FormCollection formCollection, string[] selectedEmployees)
{
if (id == null)
{
return View("Index");
}
var actvityToUpdate = db.Activities
.Include(a => a.Employee)
.Where(i => i.ActivityID == id)
.Single();
if (TryUpdateModel(actvityToUpdate, "", null, new string[]{"Employees"} ))
{
try
{
UpdateActivityEmployeeData(selectedEmployees, actvityToUpdate);
db.Entry(actvityToUpdate).State = EntityState.Modified;
db.SaveChanges();
return Redirect("Index");
//if (string.IsNullOrWhiteSpace(actvityToUpdate.))
//{
//}
}
catch (Exception exception)
{
//Log the error (add a variable name after DataException)
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists save urself");
ModelState.AddModelError("",exception.Message);
// ModelState.AddModelError("",form );
}//end catch
}
PopulateAssignedEmployeeData(actvityToUpdate);
return View(actvityToUpdate);
}//end method
[/code]
Model Activity:
[code]
public class Activity
{
//[Key]
//[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
//[Display(Name = "Nummer(willekeurig nummer)")]
//[Key]
public int ActivityID { get; set; }
[Required(ErrorMessage = "Naam moet wel ingevuld worden")]
[MaxLength(50)]
[Display(Name = "Activiteit")]
public string Name { get; set; }
[Display(Name = "Omschrijving")]
public string Description { get; set; }
[Display(Name = "uren")]
public decimal Hour { get; set; }
[DataType(DataType.Date)]
[Display(Name = "Begin datum")]
public DateTime BeginDate { get; set; }
[DataType(DataType.Date)]
[Display(Name = "Eind datum")]
public DateTime EndDate { get; set; }
[Display(Name = "Tarief")]
public decimal Tariff { get; set; }
[Display(Name = "Actief?")]
public bool Active { get; set; }
[Display(Name = "project")]
public int ProjectID { get; set; }
//public virtual DbSet<Project> Project { get; set; }
public virtual Project Project { get; set; }
public virtual ICollection<Employee> Employee { get; set; }
//public virtual ICollection<Activity> Activities { get; set; }
public virtual ICollection<Hour> Hours { get; set; }
}
[/code]
But when I try to Edit the form, for example this Object:
http://localhost:56610/Activity/Edit/4
And I post, then I get this error:
Server Error in '/' Application.
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'ManyToMany.Controllers.ActivityController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
and the routing is then:
http://localhost:56610/Activity/Edit/Index
THX
Reply
Answers (
1
)
Retrieving logged in system password using asp.net?
Convert list to datatable