View Full Version : [OPEN] [#1862] how to mix old views with new tag helpers?

Jul 10, 2021, 10:32 AM
I have views with html helpers and I want to migrate to 7.2
how can we mix html helpers with tag helpers
this code raises error:

Ext.Net.Core.Exceptions.LayoutException: Unexpected element 'TextFieldHtmlHelper' nested into 'ComponentRawContentPropertyTagHelper'.

@model ExtSample.Models.HomeModel
ViewData["Title"] = "Home page";
var X = Html.X();
<ext-section target="Main">
<ext-container flex="1">
@(X.TextField().FieldLabel("Item 1"))

Jul 13, 2021, 2:23 AM
Hello @mehdy!

I am afraid mixing up the two syntaxes is not supported. One reason is that a container's HTML is a javascript escaped string, and not really a full raw HTML code; in which some additional processing would be necessary to take place in order to convert the HTML from html helpers into a string to compose the tag helper's content, and a cyclic dependency could just happen.

You can instead, use the RenderTo() property to declare the HTML Helper somewhere else and point it to the HTML Helper's container.

For instance:

<script type="text/javascript">
Ext.onReady(function () {
<ext-panel flex="1" id="Panel1" title="My Panel">
<ext-textField fieldLabel="Item from Tag Helpers" />
@(Html.X().TextField().FieldLabel("Item from HTML Helpers").RenderTo("Panel1-innerCt"))

Notice another layout run is necessary in the container after the page is ready, as the RenderTo() is not recommended to be used against Ext.Container components because of the layout lifecycle.

So although it may be possible to craftily mix up the two syntaxes in the same page, limitations apply and they can't really be nested with each other interchangeably.

Hope this helps!

Jul 13, 2021, 6:31 AM
can we have layouts with html helpers
that also will do the job

Jul 13, 2021, 3:32 PM
Hello @mehdy!

Can you elaborate a bit on your follow-up question? I'm not quite sure I get what you want to know.

Jul 13, 2021, 7:26 PM
<ext-viewport layout="Border">
<ext-partial name="_Header" />

<ext-partial name="_Sidebar" />

<ext-section name="Main" />


This is part of the code from _layout.cshtm in the ext sample.
is there any way we can omit the tag helpers
and use just html helpers. I mean having a layout with section (Main) and Partials, all without tag helpers
if this is possible we can have all kind of layouts and embed existing views inside layouts to render pages.

Jul 14, 2021, 9:41 AM
Hello again @mehdy!

Thanks for clarifying the question. The short answer is no, there's no ext-partial or ext-section components in the HtmlHelpers space.

By one hand, HtmlHelpers could benefit directly of RenderSection() (like Ext.NET 5 MVC Examples explorer do (https://github.com/extnet/mvc.ext.net/blob/master/src/Views/Shared/_BaseLayout.cshtml)), but in the other hand it wouldn't nicely merge the component logic which is in most cases essential to a good component layout integration between Ext components.

Ext.NET 5 had ItemsFromSection (example (https://mvc5.ext.net/#/Items/Section/), example with nesting (https://mvc5.ext.net/#/Items/Nested_Layouts/)) and ItemsFromPage (example (https://mvc5.ext.net/#/Items/Page/)).

For this missing bit of functionality, we've logged issue #1862 (https://github.com/extnet/Ext.NET/issues/1862) in GitHub to track the implementation and support. This may get mixed up with the also desired Partial Views feature (https://github.com/extnet/Ext.NET/issues/1819), but if that's the case, we'll update the issue accordingly.

We'll post a follow up here as soon as we get the feature implemented.

Jul 15, 2021, 3:24 PM
Hi again fabricio
That's great news. At the end of the day we need a way to put our views (lots of views with html helpers) in some kind of layout system, so we can upgrade to new version.
Thanks again