Giter Site home page Giter Site logo

TagHelpers about entityframework.docs HOT 17 CLOSED

dotnet avatar dotnet commented on May 19, 2024
TagHelpers

from entityframework.docs.

Comments (17)

bricelam avatar bricelam commented on May 19, 2024

The tag helper documentation lives on the ASP.NET doc site.

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

I think this refers to the Getting Started with ASP.NET 5 article we have. I'm personally not a fan of tag helpers, which is probably why they aren't used in the tutorial... but I agree being consistent with the template is a good idea.

from entityframework.docs.

Eilon avatar Eilon commented on May 19, 2024

Should consult with @DamianEdwards on the best practices here.

from entityframework.docs.

Rick-Anderson avatar Rick-Anderson commented on May 19, 2024

http://docs.asp.net/projects/mvc/en/latest/views/tag-helpers/authoring.html
http://docs.asp.net/projects/mvc/en/latest/views/tag-helpers/intro.html
Early feedback on my two TH articles is great. Run through my TH tutorials and I'm sure you'll love them.

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

I have no problem adjusting the article to use tag helpers, that is definitely the right thing to do from a consistency point of view. I'm about to update everything to Beta 8 so I will do that at the same time.

Regarding liking tag helpers... for me personally it makes it too hard to distinguish between code and html. The thing I love about razor is that it's really clear what is code and it's just the same C# I write everywhere else in my application. With tag helpers that is completely obscured away.

from entityframework.docs.

Rick-Anderson avatar Rick-Anderson commented on May 19, 2024

Read my intro doc - if you're using the default or light theme, TH/C# code is in a bold purple font. If you’re using the “Dark” theme the font is bold teal. I won't repeat the other advantages here, but I'm confident after using TH you'll grow to love them.

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

GitHub doesn't know about them so I lose all that context when I'm looking at diffs, PR's etc. That's not my main issue though, if I look at this piece of markup... I have no idea what it's doing. If it was just calling APIs though I could go look at them, read Intellisense, etc.

        <environment names="Development">
            <link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.css" />
            <link rel="stylesheet" href="~/lib/bootstrap-touch-carousel/css/bootstrap-touch-carousel.css" />
            <link rel="stylesheet" href="~/css/site.css" />
        </environment>

BTW I'm not saying they don't provide value and that there aren't a bunch of folks who will like them... I'm just not one of them. I just want C# code and no magic/abstractions.

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

@Rick-Anderson quick question, how do use the asp-for when I accessing something in a for loop? It looks like the default scope is to try and access the supplied item from Model but in this case I'm enumerating over the results of the model.

Here is the code, see where I'm trying to replace @Html.DisplayFor(modelItem => item.BlogId) with a tag helper.

    @foreach (var item in Model)
    {
        <tr>
            <td>
                <label asp-for="BlogId" />
                @Html.DisplayFor(modelItem => item.BlogId)
            </td>
            <td>
                @Html.DisplayFor(model => item.Url)
            </td>
        </tr>
    }

from entityframework.docs.

Rick-Anderson avatar Rick-Anderson commented on May 19, 2024

@NTaylorMullen @rynowak can you answer @rowanmiller question?

from entityframework.docs.

NTaylorMullen avatar NTaylorMullen commented on May 19, 2024

@rowanmiller You can do: <label asp-for="@item.BlogId"></label>

from entityframework.docs.

Rick-Anderson avatar Rick-Anderson commented on May 19, 2024

@NTaylorMullen should that go in authoring TH or advanced?

from entityframework.docs.

DamianEdwards avatar DamianEdwards commented on May 19, 2024

You put an @ in front of the expression, then you can point it to whatever you like: asp-for="@item.BlogId"

from entityframework.docs.

NTaylorMullen avatar NTaylorMullen commented on May 19, 2024

@Rick-Anderson Not authoring, it's more of a usage behavior for ModelExpression properties which are used by Mvc TagHelpers.

from entityframework.docs.

dougbu avatar dougbu commented on May 19, 2024

We should not recommend foreach with expressions such as @item.BlogId or lambdas such as model => item.Url in general. They work fine in this display-only scenario but a generated <input> or <label> will have incorrect id or for attributes (respectively) and won't be bound correctly on submission. Need to mess with ViewData.TemplateInfo.HtmlFieldPrefix when using foreach. That's less straightforward than:

    @for (var i = 0; i < Model.Count; i++)
    {
        <tr>
            <td>
                <label asp-for="@Model[i].BlogId" />
                @Html.DisplayFor(model => model[i].BlogId)
            </td>
            <td>
                @Html.DisplayFor(model => model[i].Url)
            </td>
        </tr>
    }

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

Yeah the @ prefix didn't work for me either, it just displayed blank data.

It's also super weird because anywhere else @item.BlogId within markup would be resolved to its actual value by running the code and then that value used in the tag. Now I need to know that @ behaves differently depending on whether it's in a normal HTML tag or a Tag Helper.

I've swapped over to tag helpers everywhere else in #45. I'll leave this section as-is for the moment.

from entityframework.docs.

dougbu avatar dougbu commented on May 19, 2024

@rowanmiller @item.BlogId is still resolved to the expression's "actual value", just a bit later.

As soon as you type @ anywhere, Razor puts you in a C# context. The difference w/ asp-for is that you're already in a C# context, after someLambdaParameter => someLambdaParameter. (note the trailing period). After the @, you're in a different C# context -- instead after someLambdaParameter =>.

from entityframework.docs.

rowanmiller avatar rowanmiller commented on May 19, 2024

This is done in 3eba324, aside from the for loop scenario being discussed here (where it sounds like tag helpers are not the right thing to use).

from entityframework.docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.