I have the following model:
public class Product
{
[HiddenInput(DisplayValue = false)]
public int ProductID { get; set; }
[Required(ErrorMessage
In my case the cause of this problem was that assembly containing model class and main web application project had references to different versions of System.Web.Mvc assembly.
If you have couple projects referencing System.Web.Mvc assembly - ensure that used version is the same in all projects.
I had a similar problem, in my case the problem was caused because of the System.Web.Mvc reference.
I was creating a MVC 3 application, but instead of adding the version 3 of the System.Web.Mvc I added the version 4.
I too had this issue. The issue was occurring due to different versions of System.Web.Mvc in different projects of the same solution. I removed and added the references again so that it is same for all the projects(4.0.0.1).
I had the same problem.
It turned out I had version 5.2.2.0 of System.Web.Mvc in the project that contained the model and 5.2.0.0 of it in the web application project.
To install the correct version you need to run the following in NuGet package mananger:
install-package Microsoft.Aspnet.Mvc ProjectName -version X
replacing ProjectName with the name of your project and X with the version you need to install.
For example:
install-package Microsoft.Aspnet.Mvc TestProject.Web -version 5.2.2.0
If you omit the version number, NuGet will simply download and install the latest version.
Once I had done this, I also needed to update my unit test project to be on the same version as the web application project. You may need to do the same.
And in my case I had to write the [HiddenInput]
as [HiddenInput(DisplayValue=false)]
If you use scaffolding the generator will set the input tag with the type hidden in your view. This depends on the T4 Template.
If you create the view manually you must set the field manually. e.g
@Html.HiddenFor(model => model.Id)