Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

Last post 12-16-2007 2:51 AM by abombss. 8 replies.

Sort Posts:

  • Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-10-2007, 11:44 AM
    • Loading...
    • CVertex
    • Joined on 09-09-2006, 2:53 AM
    • Posts 99

    Phil, twas a great idea to use using(ActionDisposable) for creating forms. I can see this being useful for a heap of other tags too.

     

    is there something wrong with this snippet? my onsubmit handler isn't being rendered. Anyone else have the same problemo?

     
    <%using (Html.Form<RemindersController>(a => a.Create(), FormExtensions.FormMethod.post, new { onsubmit="alert('');" })) { %>

    <%}%> 

     
    I'm enjoying the ASP.NET world so much more now that I've got tight control of my HTML!

     

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-10-2007, 1:43 PM
    Answer
    • Loading...
    • robconery
    • Joined on 02-23-2005, 10:16 PM
    • Posts 175
    • AspNetTeam

    Thanks for reporting this - there indeed is a rendering bug that I just found (thanks to you!) where the passed in attributes aren't being written. I'll work to get a refreshed zip up as soon as I can - I'd like to wait and see if there are more bug reports.

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-10-2007, 6:03 PM
    • Loading...
    • CVertex
    • Joined on 09-09-2006, 2:53 AM
    • Posts 99

    Thanks Rob.

    There's like a billion overloads I can understand how'd you'd miss one case.

    While I've got your attention, I was hoping you could answer these questions:

    1. Why do I have to prefix C# keywords with underscore for helper attributes (like new {_class="blah"}? Why not @ like senor C# allows?

    2. I like the linq expression first parameter for typed ActionLinks/Forms, but I found the requirement to include a dummy parameter a bit confusing. e.g. using expression ac => ac.Create("name","blah","blah") on a Form<T>() will still correctly change the 3 arguments to the post fields. I found this cool but a bit confusing. It's like I have literals in my code that are just dummy place holders. Maybe I'm using the linq expression wrong.

    3.  I'd like to see a typed version of common attributes for HTML elements instead of always accepting object attributes. I know it'll clutter the code a bit, but it feels a bit weird passing anonymous types around. What effect does this have on performance? Having to use reflection all the time to get attributes? Is performance a concern, or is reflection quick enough? I was always encouraged to avoid reflection in rendering situations for performance reasons. I guess the tradeoff is worth it.

    4. I wrote a simple event scheduling system for my friend as an exercise, but I got stuck on paging. Do you know if ScottGu has that PagedList<T> lying around? When he's not looking, can you jump on his box and nab it for me? That's if asking him nicely doesn't work.

    Thanks,

    -CVertex 


     

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-10-2007, 6:17 PM
    Answer
    • Loading...
    • robconery
    • Joined on 02-23-2005, 10:16 PM
    • Posts 175
    • AspNetTeam

    Sure...

    1) Cause I didn't know any better :) - you can do both if you like

    2) I'd say you only want to use this type of Form constructor if those values are needed for the action. Tell me more about what you're trying to do - I think there's some confusion.

    3) Reflection can indeed be "spendy" - but it depends what you're trying to do. In this case we just grab property info from Type() and that doesn't cost that much. In terms of "typed' arguments - it would really clutter up the signatures (there are tons of attributes we'd have to account for). We can, however, overload this to take some kind of hash/List<>, but then you're cluttering up your UI.

    4) In terms of PagedList<T>: http://blog.wekeroad.com/2007/12/10/aspnet-mvc-pagedlistt/

     

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-10-2007, 6:36 PM
    • Loading...
    • CVertex
    • Joined on 09-09-2006, 2:53 AM
    • Posts 99

    Thanks for your prompt reply. 

    1. Fair enough

    2.  I'd like to use a typed action builder for my search for

    so I do

    <%using (Html.Form<RemindersController>(a => a.Search("blank"))) { %> 

    <input type=text name="query" value="enter query here"/>

    <input type=submit/>

    <%}%>

    If i press submit my RemindersController search action gets "enter query here" not "blank" . See what i mean about the unused literals?

     

    3.  If you guys think performance is a small price, then the syntactic neatness works out great for me.

     

    4. Sweet! Thanks! 

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-11-2007, 4:06 AM
    Answer
    • Loading...
    • Haacked
    • Joined on 09-17-2003, 2:43 PM
    • Posts 331
    • AspNetTeam

    In terms of performance, we do use reflection all over the place. We haven't yet performed our usual suite of stress and perf tests yet. That is definitely going to be tested before we ever release a 1.0.

    If we do find hot spots that are slow, we will probably use LCG (Lightweight Code Generation) to speed things up.

    Phil Haack (http://haacked.com/)
    Senior Program Manager, Microsoft

    What wouldn’t you do for a Klondike bar?
  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-15-2007, 4:19 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    MS MVC could add more generic expression so you could do something like this:

    public RemindersController : Controller
    {
    public void Search(string query, int page)
    {
    }
    }

    Html.Form<RemindersController,string, int>( (c, q, p) => c.Search(q, p)))
    Its a little more terse but handles your dummy scenario by not using anything.  I really haven't looked at at Html.Form enough to even know if this would work but I do know it works in Linq.

     

    Adam Tybor -- abombss.com
    Filed under: ,
  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-16-2007, 1:26 AM
    • Loading...
    • CVertex
    • Joined on 09-09-2006, 2:53 AM
    • Posts 99

    Haacked:
    If we do find hot spots that are slow, we will probably use LCG (Lightweight Code Generation) to speed things up.
     

     

    What's LCG? And how do I do that when I'm using performance critical reflection? 

  • Re: Does Html.Form<T>(lambda,Method,attributes) ignore attributes for anyone else?

    12-16-2007, 2:51 AM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    Look at DynamicMethod.  Its like reflection emit only faster without the overhead of creating a separate assembly.  There are plenty of examples using it if you google around. 

    Adam Tybor -- abombss.com
Page 1 of 1 (9 items)
Microsoft Communities
Page view counter