Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Tag Helpers: Generation for ModelExpression is incorrect when indexing #1345

Closed
dougbu opened this issue Oct 13, 2014 · 1 comment
Closed

Comments

@dougbu
Copy link
Member

dougbu commented Oct 13, 2014

When indexing into an Array or List model, MvcTagHelperAttributeValueCodeRenderer generates incorrect code. For example with a List<User> model and <textarea for="[index].Blurb" /> in the Razor source, the generated C# is:

__Microsoft_AspNet_Mvc_TagHelpers_TextAreaTagHelper.For =
  CreateModelExpression(__model => __model.[index].Blurb);

Note the extra . before [index]. This effectively limits tag helpers to simple property access.


Need to change MvcTagHelperAttributeValueCodeRenderer to leave out the . when the passed Action will write an initial [. (Can't special-case TModel to avoid breaking model => model.Count and similar expressions.)
@ escaping (issue #1253) won't help without IntelliSense. Users can't see the generated code to understand the problem.


Side note: If the user is debugging or has error pages enabled, the compilation error references a line number past the end of the .cshtml file e.g.

C:\dd\k\Mvc.1\samples\TagHelperSample.Web\Views\Home\Index.cshtml(90,112): error CS1001: Identifier expected

In my test Index.cshtml has 37 lines.

@danroth27 danroth27 added this to the 6.0.0-beta1 milestone Oct 13, 2014
@danroth27 danroth27 modified the milestones: 6.0.0-rc1, 6.0.0-beta1, 6.0.0-beta2 Oct 17, 2014
dougbu added a commit to aspnet/Razor that referenced this issue Oct 19, 2014
…ibuteValue()`

- Razor portion of aspnet/Mvc#1345

nits:
- remove a bit of trailing whitespace
- shorten lines in `TagHelperAttributeValueCodeRenderer`
@danroth27 danroth27 modified the milestones: 6.0.0-rc1, 6.0.0-beta2 Oct 20, 2014
@dougbu
Copy link
Member Author

dougbu commented Jan 11, 2015

not exact the same problem as #1253 (and #1408) but the same solution. e.g. <input asp-for="@Model[index].Blurb" /> will work once #1253 is fixed. treating this one as a duplicate...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants