1

*Solved, see Update below

I have a class with the two properties listed below:

[HiddenInput(DisplayValue = false)]
public int ProductId { get; set; }

[Required(ErrorMessage = "Please enter a product name")]
public string Name { get; set; }

When I run the solution on one machine I do not see the EditorFor ProductId when I navigate to the associated page -- When I run it on another machine (the same pull from github) I do see it (and am able to edit it). I do not want to be able to see it.

The only significant thing I think could be different on each machine is the actual database itself.

Why am I able to see my ProductId property editor on one machine but not on the other while using the same code?

Note

MVC renders the view differently on each machine (the generated HTML is different - this reflects the discrepancy above).

Update

Solved the problem, see my answer below.

Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
  • I just ran into a very similar problem with a co-worker, but in MVC 4. We had different versions of the frameworks installed. This is less likely with MVC 3, but it might be worth a check. By any chance, did one of you have a pre-release installed? – MisterJames Jul 10 '12 at 16:11
  • @MisterJames One machine has MVC4 installed, while the other just has MVC3. I did not think this would cause any issues when the solution itself is copied directly from one machine to the other. – Ecnalyr Jul 10 '12 at 16:33
  • No, this shouldn't. Our issue was different versions of MVC4, '4.0.20126.16343' vs '4.0.20505.0'. Sorry, just wanted to rule that out. – MisterJames Jul 10 '12 at 16:43
  • 1
    why not use `@html.hiddenFor(x => x.productId)` instead `editorFor` – Zach dev Jul 10 '12 at 17:05
  • @Zachdev Because I should not have to. . . and it works on one machine, why not expect it to work elsewhere? – Ecnalyr Jul 10 '12 at 17:41

2 Answers2

1

Figured it out. . . kind of.

Oddly enough, I had another problem elsewhere in the app after trying to move on for a while. That problem and MisterJames' comments on the original question led me to this answer.

To make things simple, I just uninstalled MVC4 from the machine that was giving me issues (I did not have MVC4 installed on the other machine) and both of my problems went away.

Community
  • 1
  • 1
Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
1

I had a similar issue where I added the [HiddenInput(DisplayValue = false)] annotation to a productId property in a class in my model. The model was a separate project from my MVC project. In order to get the annotations I had to include a reference to System.Web.Mvc but I had included v. 4.0.0.0 while my MVC project was v. 3.0.0.0

This caused the annotation to not work even though all projects would compile and all other functionality remained intact.

I fixed this by editing the .csproj file for my model project, switching the version of the included reference from 4.0.0.0 to 3.0.0.0. This could also be accomplished by removing the reference to the wrong version and re-adding the correct one.

seangwright
  • 17,245
  • 6
  • 42
  • 54