DISQUS

Rob Conery: ASP.NET MVC DropDownList and HTML Attributes : Rob Conery

  • Stephen · 1 year ago
    DataTextField and DataTextValue? where did those come from? I can't stand these methods for building html anyway, its one thing I'm well avoiding in the mvc.. that and the binding system.
  • robconery · 1 year ago
    If you could elaborate a bit on what you don't like, it would help. Like any
    tool, you can make a mistake (especially with a beta toolset) and it can be
    icky. However we are in beta still so your feedback is welcomed.
  • glompix · 1 year ago
    I, for one, just think it looks rather untidy to have a lot of <%= %> in my code. The anonymous object => html attributes is a really neat idea too, but again to me it is just amidst all that markup.

    We have an MVC app that has some pretty monster html forms, so I like to limit my <%= BlahHelper.foo() %> to just things that really take a lot of space or logic to render. For textboxes, hidden fields, and other run-of-the-mill controls, I have some server controls that do a lot of what HtmlHelper controls do, (binding, attribute inferring, etc...) with a little tweaking for internal stuff and a read-only mode for detail views.

    Good luck on your book, btw; with you three writing that I can't imagine buying anything else. :)
  • Elmar · 1 year ago
    Well, actually I am a big fan of <%= %>. It is a lot easier to distinguish from HTML/XHTML. Custom Tag Libs and server controls (which are also custom tags with a runat attribute) tend to blend in to much into static HTML/XHTML although they are an absolute different type of animal.

    Designers I worked with in the past just knew that they should avoid touching anything that comes in <% %> brackets - but they regularly tried to mess with custom serverside tags.

    At the end it is all a matter of personal taste, right ;-))

    cheers,
    Elmar
  • glompix · 1 year ago
    That I can certainly understand. At my old company, designers never really touched the markup after it had moved hands to the developers, so I've never really thought about that situation. That was a jsp/Stellent shop where nobody but the developer could understand what was going on anyway. :)

    You say new { foo = "to-may-to" }, I say <... foo="to-mah-to"/> applies here.
  • James · 1 year ago
    <%=Html.DropDownList("CategoryID"])%>

    spelling error? additional close bracket?

    thanks for this,

    id LOVE to see this book, hopefully it has some good insight into the best ways for cascading dropdown and
    check box lists!
  • Matt · 1 year ago
    Is it possible to preview your book using Wrox First?
  • robconery · 1 year ago
    Sure - it's on the link:http://www.wrox.com/WileyCDA/Section/id-321793.html

    You can read a sample chapter (that we're updating now). It's a bit rough,
    but there's a sample there.
  • Lamin Barrow · 1 year ago
    Awesome.. i have been checking 20 times everyday on this blog over the last little while. Thanks for the latest updates rob. I could really use this stuff . :)
  • Lamin Barrow · 1 year ago
    BTW... i hope you (and Haacked and Scott) get much success with your book.
  • huey · 1 year ago
    I just updated from Preview 5 to Beta and had a problem with the htmlhelpers. Granted, it isn't nearly as interesting as this one.

    Specifically, the textbox helper overloads to something like string name, object value, object htmlattributes when it was previously string name, object htmlattributes (which is now string name, object value). My htmlattributes ended up being added to the value field during the recompile, which isn't a big deal. The annoying thing is that now to add the value parameter you basically need to test the model for null and then specify the actual property or you get an exception trying to reference a property from a null object. It becomes pretty verbose and I hope there is a better method I'm not thinking of, or that a better solution is in the release.
  • FloK · 1 year ago
    Wow, that SQLed HTML looks really scary.
    I run into the same issue with the object overload. It's about time for a better (i.e. Ruby like) syntax for dictionaries in C#.

    This is the first time I heard about SelectList. Probably I missed a MVC StoreFront episode.
  • mike · 1 year ago
    Heh, stuff like that will make a programmer end up on the daily wtf...
  • chrisntr · 1 year ago
    I am curious how you guys find these sort of bugs - as you say - you only found these out by trying to do a simple solution until you saw this bug. Is it through just end-users testing it or is it a more rigorous process?
  • robconery · 1 year ago
    Nope - I literally found it as I viewed source on an HTML page so I could copy/paste the code for a code sample.
  • Javier Lozano · 1 year ago
    I've run into the same issues with ActionLink and the passing of routevalues into the generation of the link. The work around for that is proving a null for the htmlAttributes parameter.
  • Thomas · 1 year ago
    Thanks for sharing Rob ... I think I would be mad if this happened to me :-)
  • skaue · 1 year ago
    Wouldn't a ToList() solve this? Like this.
    var categories = (from c in db.Categories select c).ToList();
  • robconery · 1 year ago
    It would solve the SQL Issue, but you'd have all the List<T> properties
    added to the HTML as attributes. Better, for sure - but doesn't solve it.
  • skaue · 1 year ago
    LOL... thats true... >.<
  • John · 1 year ago
    And, of course, a good number of us never liked this anonymous object business to begin with.
    http://weblogs.asp.net/leftslipper/archive/2007...
  • Chase · 1 year ago
    <%= Html.DropDownList("CategoryId", (SelectList)ViewData["Whatever"]) %>
  • robconery · 1 year ago
    Hi Chase - that will work, except if it's null.
  • ambikaa · 1 year ago
    Hi,

    Nice example. Could you please show me the code to display result based on the dropdownlist selected value? How to do the dropdownlist selection changed?
  • owais · 1 year ago
    I tired to work the same code with html.Radiobuttonlist()
    and all i get is this "System.String[]"
    now i tried this with looping as well but then it wont render and names beside the radio button..
  • almny · 7 months ago
    i don't know weher's the post ?
  • Altaf · 5 months ago
    The article here shows how to set the dropwdownlist:
    http://altafkhatri.com/Technical/How_to_bind_IL...