ASP.Net [HiddenInput] Data Attribute not working when rendered with Html.EditorForModel in Razor?

后端 未结 6 600
情歌与酒
情歌与酒 2021-01-11 18:01

I have the following model:

public class Product
{
    [HiddenInput(DisplayValue = false)]
    public int ProductID { get; set; }

    [Required(ErrorMessage         


        
6条回答
  •  温柔的废话
    2021-01-11 18:33

    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.

提交回复
热议问题