I found a similar question here: Razor View Engine : An expression tree may not contain a dynamic operation
But I have tried the solutions and they do not solve my issue. I have a Controller with the following:
public ActionResult CreateOrganization(Guid parentOrganizationId)
{
Organization organization = new Organization();
return View(organization);
}
And the view has the following:
@using Project.Data
@Model Project.Data.Organization
@{
ViewBag.Title = "Create new Organization";
}
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>Use the form below to create a new Organization.</h2>
</hgroup>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Html.BeginForm((string)ViewBag.FormAction, "Organization"))
{
<fieldset>
<legend>Create Organization</legend>
<ol>
<li>
@Html.LabelFor(m=> m.Name)
@Html.TextBoxFor(m=> m.Name);
@Html.ValidationMessageFor(m=> m.Name)
</li>
</ol>
<input type="submit" value="Register" />
</fieldset>
}
Which is explicitly specifying the model (as suggested in the other post). However I am still receiving the 'An expression tree may not contain a dynamic operation' error. Have I made a stupid mistake somewhere?
Your View seems incorrect.
The model declaration should be lowercase 'model', not 'Model':
@model Project.Data.Organization
The fix is
@model ProjectName.Models.Modelname
Models >> if use model class in in model folder ProjectName.MVC Model path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With