Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Overview
I have a routine that produces a basic HTML page. This page contains a piece of code like:
HTML
<input type="text" asp-for="ModelValue" />

So, the above code is embedded in an HTML value that is *inside* another string, which I am passing into the view and doing:
Razor
@Html.Raw(Model.MyHTMLString)

The Problem:
My issue is that the string inside the model that I am trying to surface isn't resolving the "asp-for" tags.
My question(s):
  1. How can I manually call for the processor to execute after I've presented this HTML on the view?
  2. Alternatively, how can I take the HTML that I am generating and prepare it BEFORE I send it to @Html.Raw?
  3. Or even other alternatively, how else can I approach this?
    What I've tried:
    • parsing through a partial view
    • parsing through SetHtmlContent(my string)
    • parsing through SetContent(my string) (wow, was that a mess...)
    • sending my string through without using Html.Raw (no effect - same as using it)


Other Disclaimers
I'm new at using views in .NET. I'm normally an MC guy, not an MVC guy. I do a lot of C# coding, but not so much HTML. I mean, I "get" HTML somewhat, but would normally build it by hand (Old school.)

Any help that anyone can give would be VERY greatly appreciated.

Thanks.
-J

What I have tried:

  • parsing through a partial view
  • parsing through SetHtmlContent(my string)
  • parsing through SetContent(my string) (wow, was that a mess...)
  • sending my string through without using Html.Raw (no effect - same as using it)


Edit: I think I'm understanding part of my problem...
It would seem that what's happening is that my markdown is rendering effectively "in order" of what's on the Razor page. And since the markdown isn't "aware" of the model, it can't offer much in the way of help for that. I think I need to incorporate my own tag handling inside the markdown... Thoughts?
Posted
Updated 12-Oct-23 11:05am
v5

This should answer your question: Dynamically assigning asp-for variables[^].

Here is the Google search used: asp.net dynamic asp-for - Google[^]

UPDATE

This may help: Creating dynamic forms with .net.core[^] and the Google search used: asp.net core dynamic form builder - Google[^]
 
Share this answer
 
v2
Comments
James McCullough 12-Oct-23 19:08pm    
Nope, that's not the issue. The issue is that the tags aren't running on the parsed code. I'm presenting the parsed code through Html.Raw, and the asp-for tags aren't being picked up. Stuff that's NOT in the Html.Raw code is... So unfortunately, this isn't my issue.
Graeme_Grant 12-Oct-23 19:25pm    
I think that you missed the point. Dynamic is post compiler, not pre. This is why.
Graeme_Grant 12-Oct-23 19:41pm    
I've had another look and updated my solution.
If you want to parse Razor tags in a string, you'll either need to use the full Razor engine, or use a library like RazorLight[^] or RazorEngine[^] to parse the string.

Alternatively, if you just want to load your views from a database, you could create a custom file provider:
Loading ASP.NET Core MVC Views From A Database Or Other Location[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900