MVC Helper Templates

In my experiences with MVC I have some utilities to share . Some of them are :

  • DateTime fields
  • Numeric fields
  • Watermark
  • Dropdownlist
  • more!

Please see the project and give feedback

MvcHelperApplication


Posted

in

,

by

Comments

22 responses to “MVC Helper Templates”

  1. […] This post was mentioned on Twitter by ignatandrei, GabiEnescu. GabiEnescu said: Ignat Andrei EN blog:: MVC Helper Templates http://msprogrammer.serviciipeweb.ro/2010/05/30/mvc-helper-templates/ http://bit.ly/dzUcxa […]

  2. Krokonoster Avatar

    Thanks for posting this and making things so clear via examples.
    One question at this stage: In the DateTime display template, you format dates as “dd MMM yyyy”.
    Shouldn’t one rather format it according to the user’s current culture info settings?

  3. admin Avatar
    admin

    Oh, yes. Like the numeric, you can do the same. I just want the example to be more “evident”!

  4. Krokonoster Avatar

    Hi,
    Ok, I’ve been fiddling with your examples (very educational experience, not only for Templated Helpers but also jQuery datapicker and others 🙂 )

    I found one should use the WaterMarking with caution (maybe only for showing a date format), as it kind of messed with my validation.

    The DateTime helper I took out eventually. Reason is that on one place I want the user to select date of birth, on another place a user to specify a date range (say a booking)…the different options to be set mad it kind of impossible to use a generic template. (Or did I miss something obvious).

    Once again, this is good stuff. Continuing my venture and come back with some more comments. 🙂

  5. dhanaji Avatar

    Hi ,

    I am using watermark in our MVC application. It works fine in IE. I am facing one issue in FireFox and Chrome.

    I am using watermark on our login page. I want watermark for username which is first textbox control on a page.When page loads username is focused by default, so watermark is not visible when page loads, if you click somewhere else it appears.This is happening in firefox and chrome only. I am not sure whether it is default behaviour of browser, but in IE username is not focused when page loads so there it appears fine.

    Thanks,
    Dhanaji

    1. Andrei Ignat Avatar
      Andrei Ignat

      This is a browser issue, and the behaviour is normal

  6. dhanaji Avatar

    Hi,

    How to override this browser issue? appreciate your help

    Thanks,
    Dhanaji

    1. Andrei Ignat Avatar
      Andrei Ignat

      Unfortunately not .. But you can search for another watermarking “persistent” plugin : does not hide until the user types something

  7. PeterG Avatar
    PeterG

    Hi Andrei – great controls! I’m looking to use the Calender control in my project but as an MVC newbie I’m really struggling.
    So far I have added & imported, EditorTemplates, DisplayTemplates, calendar.gif – all to the correct paths (I think!).
    I’ve got Html.EditorFor mapped to a DateTime field yet only a normal textbox gets displayed. It’s as if the new control isn’t doing it’s overriding job. Am I missing any .css or script files Andrei?
    Cheers for your help,
    Pete

    1. PeterG Avatar
      PeterG

      P.S. It’s MVC 3

  8. Ryan Avatar

    Thank you Andrei. Everything works great in IE. Is there any way to convert these to work in other browsers like FireFox consistently without any issues?

  9. james Avatar

    look forward to the series. I especially am interested in the “Areas” part of your series.

    I tried to use them a while back (early preview), but there still seemed to be things to be ironed out.

    I had wanted to use an Area to slowly migration from ASP.NET WebForms project to ASP.NET MVC. I was trying to put all the MVC stuff (MasterPages, CSS, Styles, Views, Controllers, Models, etc…) in an Area while keeping the WebForms stuff in the main root project.

    It seemed like a good idea at the time, but I had strange issues. Possibly I was using an Area for the wrong thing.

  10. James Avatar

    >>>>>>>> That looks so clean. So would I be able to assume it’s a two way binding on both response request?

    Glad you like it! The helpers can be used to help assist with two-way binding. In my next blog post I’ll cover some of the new validation features of ASP.NET MVC 2 – which will help provide a better sense of how end to end input works.

    Hope this helps,

    Scott

  11. James Avatar

    look forward to the series. I especially am interested in the “Areas” part of your series.

    I tried to use them a while back (early preview), but there still seemed to be things to be ironed out.Thank you Andrei. Everything works great in IE. Is there any way to convert these to work in other browsers like FireFox consistently without any issues?which will help provide a better sense of how end to end input works.

    Hope this helps,

  12. james Avatar

    When using the template helpers in ASP.NET MVC, e.g.

    Html.EditorFor(x => x.Property)
    the rendered Html with have a capitalized ID – matching my property name.
    In order to standardize the ID’s of all html elements I want this to be lower case. Rather than specifying the ID manually – which won’t get updated if I rename my property, I’d like to establish a convention.

    I’m sure I read this was possible somewhere and I’m currently scanning the interwebz to find it. But if anyone can help me and save me time, that would be awesome.

  13. Allen Avatar

    EditorTemplates
    DisplayTemplates
    calendar.gif

    all added and imported.

    I had a problem with the datetime field same as the issue above. The normal textbox gets displayed. I was thinking that I am missing something like .css. after reading and some research I got it all figured out! Thanks for this andrei!

    1. Manu Avatar
      Manu

      I can’t make it show up, using MVC3, I spent this entire night fighting wit it.

      If someone has a solution, please share, thank you so much!

      1. Manu Avatar
        Manu

        I finally found it… on the Layout page I had this include:

        Changed it with 1.6.2 and all worked like expected.

        Maybe this note will save time and nerves to somebody else.

  14. Antti Avatar
    Antti

    Thank you! If only I had found your post a couple of hours earlier…

  15. MN Avatar
    MN

    Thank you! it’s good as well as working fine.

  16. Shweta Avatar

    I am using water mark at the time of validation as well.

    The case is when i Press save button red outline of text box should appear with water mark .
    When i use this text box i could not validate it.
    Please suggest me .

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *