Monday, January 03, 2011

CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage.Model'

CS0135: 'Model' conflicts with the declarationSystem.Web.Mvc.ViewPage<TModel>.Model
After spending couple of hours I found the solution, before my try I tried all the option suggested on internet like: add the namespace with the class which you are using
Inherits="System.Web.Mvc.ViewPage<Attachment>"  and add a
<%@ Import namespace="MyProject.Models" %> Or
Inherits="System.Web.Mvc.ViewPage< MyProject.Models.Attachment>" 

But for me problem was different, the problem was
Cause
I used validation control (ValidationMessageFor) to and passed wrong parameter with "=>" expression like:
Line -1: <%= Html.ValidationMessageFor(Model => Model.Employee)%></div>

Line -2: <% Html.RenderPartial("Attachment", Model ); %> 
Because of Line -1: mistake Line -2: was giving error "CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage<TModel>.Model"
Solution
I correct above line like below
<%= Html.ValidationMessageFor(Employee=> Model.Employee)%></div>

<% Html.RenderPartial("Attachment", Model ); %>
It was very stupid mistake but its took longer time to analyzed, Now my page is working fine.

2 comments:

Anonymous said...

Thaks man its useful

Unknown said...

Thank you very Much it really helps