Another comment on the new method UpdateModel(). I often use the overload where one can pass an objectPrefix: UpdateModel(object model, string[] keys, string objectPrefix)
New in Preview 5, there must be a point ('.') between the objectPrefix and the member name (string fieldName = (String.IsNullOrEmpty(objectPrefix)) ? key : objectPrefix + "." + key; Controller.cs line 336). In Preview 4, this point wasn't mandatory, and I remember
having some issues with jQuery not properly handling elements whose id contained a point (I think the jQuery selector $() has some problems with it, as a point is also used as a marker for css class names).
Do you think it would be possible that in the next Preview (in the beta), one can use both notations, with and without point between objectPrefix and the member name?
Nobody answered to my post...perhaps someone from the development team could give me a short feedback about this issue? Will this be modified in the beta release, or not?
At the moment, this is the only reason that hinders us from using the UpdateModel function. Did anybody encounter similar problems with jQuery and the infamous dot?
I doubt that we'll stop using a dot as a delimiter for the element name. A possible solution to this would be for us to sanitize the 'id' attribute before we output it - or perhaps for us to leave the 'id' attribute off altogether.
This is not viable. Using an empty string as a delimiter means that we can't tell where property names begin or end. We also can't use underscores since the member names of the types we're serializing / deserializing might contain one.
@tolstoi, you are incorrect. using $() does not find elements based on the
name of the element, it uses the id or class, such as $('#id') or $('.class1.class2'). As you can see, using dots in the id is ambiguous because $('#A.B') will try to find an element with id=A and class=B.
The way that the MvcContrib project handles this is, when you use a helper to render a form element with the name "prefix.Property", it sets the id of the element to "prefix-Property", simply replacing
dot with hyphen.
Doing this only affects the client side javascript, because when the form is posted the values have the correct name. This means UpdateModel etc continue to work as they do.
Levi, what do you think? id = name.Replace( ".", "-" )
PS You can match by name using $('*[name="name"]') and that is unambiguous, it doesn't matter if the name contains dots using this syntax !
@tgmdbm: I never said that jQuery's $() finds elements by name. The id of the elements is the problem. I like the idea of replacing the dots by "-" within the ids! This would resolve our issue! Thanks.
tolstoi
Member
2 Points
18 Posts
UpdateModel objectPrefix
Sep 05, 2008 03:35 PM|LINK
Hi everybody,
Another comment on the new method UpdateModel(). I often use the overload where one can pass an objectPrefix: UpdateModel(object model, string[] keys, string objectPrefix)
New in Preview 5, there must be a point ('.') between the objectPrefix and the member name (string fieldName = (String.IsNullOrEmpty(objectPrefix)) ? key : objectPrefix + "." + key; Controller.cs line 336). In Preview 4, this point wasn't mandatory, and I remember having some issues with jQuery not properly handling elements whose id contained a point (I think the jQuery selector $() has some problems with it, as a point is also used as a marker for css class names).
Do you think it would be possible that in the next Preview (in the beta), one can use both notations, with and without point between objectPrefix and the member name?
Thanks.
tolstoi
Member
2 Points
18 Posts
Re: UpdateModel objectPrefix
Sep 16, 2008 06:29 AM|LINK
Hi again,
Nobody answered to my post...perhaps someone from the development team could give me a short feedback about this issue? Will this be modified in the beta release, or not?
At the moment, this is the only reason that hinders us from using the UpdateModel function. Did anybody encounter similar problems with jQuery and the infamous dot?
Thank you.
levib
Star
7702 Points
1099 Posts
Microsoft
Re: UpdateModel objectPrefix
Sep 16, 2008 07:16 AM|LINK
I doubt that we'll stop using a dot as a delimiter for the element name. A possible solution to this would be for us to sanitize the 'id' attribute before we output it - or perhaps for us to leave the 'id' attribute off altogether.
tolstoi
Member
2 Points
18 Posts
Re: UpdateModel objectPrefix
Sep 16, 2008 07:59 AM|LINK
Thanks for your answer, levib.
Another solution would be to allow both the dot ('.') and nothing ('') (and/or the underscore ('_')) as a delimiter. Or is that not viable?
levib
Star
7702 Points
1099 Posts
Microsoft
Re: UpdateModel objectPrefix
Sep 16, 2008 08:30 AM|LINK
This is not viable. Using an empty string as a delimiter means that we can't tell where property names begin or end. We also can't use underscores since the member names of the types we're serializing / deserializing might contain one.
Thanks for the feedback!
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: UpdateModel objectPrefix
Sep 16, 2008 04:02 PM|LINK
@tolstoi, you are incorrect. using $() does not find elements based on the name of the element, it uses the id or class, such as $('#id') or $('.class1.class2'). As you can see, using dots in the id is ambiguous because $('#A.B') will try to find an element with id=A and class=B.
The way that the MvcContrib project handles this is, when you use a helper to render a form element with the name "prefix.Property", it sets the id of the element to "prefix-Property", simply replacing dot with hyphen.
Doing this only affects the client side javascript, because when the form is posted the values have the correct name. This means UpdateModel etc continue to work as they do.
Levi, what do you think? id = name.Replace( ".", "-" )
PS You can match by name using $('*[name="name"]') and that is unambiguous, it doesn't matter if the name contains dots using this syntax !
levib
Star
7702 Points
1099 Posts
Microsoft
Re: UpdateModel objectPrefix
Sep 16, 2008 04:17 PM|LINK
There's a proposal to do something similar to this - I'll see if I can bump it up a notch in priority.
tolstoi
Member
2 Points
18 Posts
Re: UpdateModel objectPrefix
Sep 16, 2008 05:21 PM|LINK