Reputation: 341
I've been getting this error message 'Error 2'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model' and I can't figure out how to fix it.
public partial class Person
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2214:DoNotCallOverridableMethodsInConstructors")]
public Person()
{
}
public int PersonID { get; set; }
public string FullName { get; set; }
public string FirstName { get; set; }
public virtual EHR_Gender EHR_Gender { get; set; }
public int GenderID { get; set; }
public virtual Gender Gender { get; set; }
}
I created this partial class and add the GenderData property to be able to pass a list of SelectList items.
public partial class Person
{
public IEnumerable<SelectListItem> GenderData { get; set; }
}
I am getting the conflict error message in the below piece of code.
@Html.DropDownListFor(m => m.Gender.Description, Model.GenderData, new { @class = "form-control" })
I have searched on Google for a solution. The majority of the fixes have something to do with someone using 'model' instead of 'Model'. This is not the case for here.
Upvotes: 0
Views: 78
Reputation:
The code you have shown will not result in that error. Its generated because somewhere in you view you have used a HtmlHelper
method with an expression using capital M
Model, followed by another reference to @Model
, for example
@Html.TextBoxFor(Model => Model.SomeProperty)
....
<div>@Model.AnotherProperty</div>
Note also that if you swapped the order of the above elements, you would get a different exception.
Upvotes: 1