0

I have a domain model in a DLL that I want to keep separate from my main ASP.NET MVC project.

I want to decorate the properties in this model with metadata attributes (such as DisplayName, UIHint, DataType, etc.). This is so that I can call EditorForModel to have these properties properly rendered in my ASP.NET MVC View.

Most of the attributes are available in the namespace System.ComponentModel.DataAnnotations but to my surprise, [HiddenInput] is NOT part of this namespace. It seems that [HiddenInput] is only in System.Web.Mvc (which I cannot reference from my stand-alone domain model DLL).

My domain model is in its own separate DLL class, and I don't want to move it inside my ASP.NET MVC project.

What other solutions do I have if I want to flag certain attributes in this model as "hidden" so that EditorForModel can recognize it (and hide it) when rendering the view?

1 Answer 1

1

You could try the UiHintAttribute that resides in the DataAnnotations namespace

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.uihintattribute(v=vs.110).aspx

[UIHint("Hidden")]
public int ID { get; set; }

HTH

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your response, @Slicksim. Will EditorForModel be able to recognize [UIHint("Hidden")] and hide the field when rendering the view?
If you use the mvc standard template, I.e. dont provide a template it will. If you use editorfor in your own template, it will use the uihint to output the hidden
I used Editable(false)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.