Controller code:
public ActionResult Edit(int id)
{
Users result = null;
using (MyApplicationContext context = new MyApplicationContext())
{
ViewBag.Conditions = context.Conditions.Where(x => x.IsActive).OrderBy(x => x.Name).ToList();
result = context.Users.FirstOrDefault(x => x.Id == id);
}
return View("Manage", result);
}
In the view, Manage.cshtml, I have the following code.
@using MyApplicationContext.Models
@model MyApplication.Models.Users
@{
ViewBag.Title = "Manage";
List<MyApplication.Models.Condition> conditionList = ViewBag.Conditions;
foreach (var condition in conditions)
{
bool isChecked = Model.Conditions.Any(x => x.Id == condition.Id) ? true : false;
}
The code is failing on the assignment to isChecked in the foreach loop, but in the editor, Model description is 'Gets the Model property of the associated ViewDataDictionary object.
I don't understand how this is tied to the ObjectContext object. When I remove it, the code which references model (lowercase from @model) is successful.
Thank you,