MVC3: What does the UIHint attribute do?

Posted on 2012-09-20
Last Modified: 2012-09-21
What does this attribute do in an MVC3 app?

       [UIHint("ProductViewModel"), Required]
Question by:newbieweb
    LVL 38

    Accepted Solution

    UIHint specifies a template for editor or display for the field.  In this example, assuming Product is the name of the field, when you call

    @Html.EditorFor(model => model.Product)

    it will pick up the template from the appropriate EditorTemplates folder.  Same for DisplayFor method.  

    There's a good explanation here:
    LVL 96

    Assisted Solution

    by:Bob Learned
    The interesting thing that I have learned about display templates, and the default behavior, is if you have a view model class, and a display template with the same name, the template will be used.  This "magic" configuration can be confusing when troubleshooting an issue.  I am starting to think that explicitly specifying a template, gives you a "hint" to the display template, so that you know which one is giving you trouble.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now