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

Generates wrong place quotation mark of attribute in template #691

Closed
riwofeb opened this issue Feb 13, 2016 · 2 comments
Closed

Generates wrong place quotation mark of attribute in template #691

riwofeb opened this issue Feb 13, 2016 · 2 comments
Assignees
Milestone

Comments

@riwofeb
Copy link

riwofeb commented Feb 13, 2016

the following code demonstrate it:
ViewComponents\SimpleViewComponent.cs

...
    public class SimpleViewComponent : ViewComponent
    {
        public IViewComponentResult Invoke(SimpleData sd)
        {
            return View(sd);
        }
    }
    public class SimpleData
    {
        public string Title { get; set; }
        public int Count { get; set; }
        public Func<dynamic, object> ContentHtml { get; set; }
    }
...

Views\Shared\Components\Simple\Default.cshtml

...
@model SimpleData
...
<h4>@Model.Title</h4>
<ul>
    @for (int i = 0; i < Model.Count; i++)
    {
        <li>@Model.ContentHtml($"Item #{i + 1}")</li>
    }
</ul>
...

Views\Home\SimplePage.cshtml

...
@{
    var extaClass = "text-success";
    @* My template *@
    Func<dynamic, object> content =
        @<text>
        <p class="text-capitalize @extaClass" style="font-size: 110%; font-weight: 600">
            @item
            <span style="font-size: 80%; color: #bbb">[Hint of title.]</span>
        </p>
        <p>...</p>
        </text>;
}
...
<hr />
@(Component.Invoke<SimpleViewComponent>(new SimpleData() { Title = "View Component title.", Count = 3, ContentHtml = content }))
<hr />
@content("This separate item!")
...

and when SimplePage.cshtml rendered you will see the following wrong html:

...
<hr />
"""
    <h4>View Component title.</h4>
    <ul>
            <li>

        <p class="text-capitalize text-success style="font-size: 110%; font-weight: 600">
            Item #1
            <span style="font-size: 80%; color: #bbb">[Hint of title.]</span>
        </p>
        <p>...</p>

            </li>
            <li>
...
<hr />
        <p class="text-capitalize text-success" style="font-size: 110%; font-weight: 600">
            This separate item!
            <span style="font-size: 80%; color: #bbb">[Hint of title.]</span>
        </p>
        <p>...</p>
...

The @(Component.Invoke<... not rendered end quotation mark of class attribute (where text-success), ie generator move it to wrong place after <hr />.
But @content("This separate item!") rendered success, ie quotation mark in its place.

@Eilon
Copy link
Member

Eilon commented Feb 21, 2016

cc @NTaylorMullen in case you have thoughts on this too.

@NTaylorMullen
Copy link
Member

Looks like a code generation bug. We're unconditionally rendering the EndWriteAttribute method here. When in fact we should be rendering the EndWriteAttributeTo variation if !string.IsNullOrEmpty(Context.TargetWriterName). Much like what we do for the BeginWriteAttribute variation.

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

4 participants