I created scaffold delete view for delete but it doesn't work. When debugging I found that It doesnt pass the correct ID of the record to controller. Always it passes 0 as the ID and result is an exception (ystem.NullReferenceException was unhandled by user code Message=Object reference not set to an instance of an object.) .
But in the view submit button shows the correct URL with correct ID.
Controller:
public ActionResult DeleteSubject(int id)
{
try
{
// returns the View
}
catch (Exception e)
{
// Handle and log the exception
}
}
[HttpPost]
public ActionResult DeleteSubject(SubjectModel subject)
{
try
{
// Call methods for delete
}
catch (Exception e)
{
// Handle and log the exception
}
}
View:
@model LMS.Models.SubjectModel
// ... form elements go here
@using (Html.BeginForm()) {
<input type="submit" value="Delete" />
}
When debugging the [HttpPost] method with a break point, object taken by the method as argument seems not initialized with values. Displaying 0s for ID fields and null for other fields.
Worked on recreating views, rewriting controller methods, changing attributes etc. But still get the issue. Appreciate your input.
(BTW created scaffold view for Create, List and Edit. They are working perfectly.)
Thanks,
Chatur