Try our conversational search powered by Generative AI!

Issue with tag helpers in EPiServer page views

Vote:
 

When we try to use a tag helper in a episerver view, for example <form asp-controller="MyController" asp-action="MyAction"> never forms a valid action. If we hardcode <form action="/MyController/MyAction" it works. The <form> attrubute works for any of our non-EPiServer controllers/Views.

#319543
Mar 26, 2024 13:27
Vote:
 

Hi Eric

what action did you get in the markup?

#319582
Edited, Mar 27, 2024 5:06
Eric - Mar 27, 2024 13:06
The action is blank. It won't even create one.
Vote:
 

Hi Eric,

Have you made taghelpers availabe by adding 

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

to the '_ViewImports.cshtml'? or similar.

#319587
Mar 27, 2024 10:42
Vote:
 

Yes. the form <form> and anchor <a> taghelpers and others are auto-colored and autocomplete when typing. They just don't create the action or href when inspecting using devtools in browser.

#319590
Mar 27, 2024 13:11
Vote:
 

Eric,

I am not sure if this is it however it seems to recreate the experience you are explaining.

If I set the asp-controller and asp-action to something that doesn't exist in my solution if does not render e.g. this setup does not exist in a default alloy site:

<form asp-controller="Demo" asp-action="Register" method="post">
    <!-- Input and Submit elements -->
</form>

Renders

    <form method="post" action="">
        <!-- Input and Submit elements -->
  </form>

Changing to something that does exist I get:

 <form asp-controller="StartPage" asp-action="Index">
     <!-- Input and Submit elements -->
 </form>

Renders

 <form action="/modules/App/StartPage" method="post">
        <!-- Input and Submit elements -->
 </form>

In this blog it does mention that this works based on the application's routing configuration https://www.learnrazorpages.com/razor-pages/tag-helpers/form-tag-helper

That would explain why this didn't work as that route has not been defined in my solution.

#319595
Mar 27, 2024 17:27
Vote:
 

Hi Eric

You might miss the ASP.NET MVC conventional route config in your startup if you're going to use standard Asp.Net Mvc route. 



#319632
Edited, Mar 28, 2024 0:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.