I have searched SO for similar posts and have not been successful with any given solutions. So I have posted this again.
I am trying to post some information back to the database in this Controller Action. This Action is called when Save button is clicked on the View.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditDetail(int id, FormCollection fvals)
{
Environments env = environmentsRepository.GetEnvironmentDetail(id);
UpdateModel(env);
environmentsRepository.Save();
return RedirectToAction("List", new RouteValueDictionary(new
{controller="Environments", action="List", id = 1}));
}
When I click on the Save button, I get the following error:
Line 32:
Line 33:
Line 34: <% foreach (var environment in Model) <--Error in this line
Line 35: { %>
Line 36:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP.views_environments_list_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in e:\code\ossp\WebUI\Views\Environments\List.aspx:34
Please let me know what I am missing? How do I resolve the error?
List View:
http://pastebin.ubuntu.com/544767/
List Action:
http://pastebin.ubuntu.com/544768/
Resolution:
I have realized that I was passing the wrong parameter 'id' instead of 'page', to the List view.
Thanks everyone for their pointers. I was able to learn a lot due to this discussion. Unfortunately, I am still at 11 to be able to give some votes. Thanks!
return View(); ///TODO Handle This. in this case the model is empty