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

后端 未结 6 569
情歌与酒
情歌与酒 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:26

    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.

    0 讨论(0)
  • 2021-01-11 18:32

    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.

    0 讨论(0)
  • 2021-01-11 18:32

    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).

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-11 18:34

    And in my case I had to write the [HiddenInput]as [HiddenInput(DisplayValue=false)]

    0 讨论(0)
  • 2021-01-11 18:52

    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)
    
    0 讨论(0)
提交回复
热议问题