Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Razor to resolve symbol @Model?

Tags:

c#

razor

I have a Razor .cshtml template with the following:

enter image description here

As you can see, @Model can't be resolved.

However, when I parse the template with the following code:

public static string RenderPartialViewToString(string templatePath, string viewName, List<ZonesVM> zonesVm)
{
    string text = File.ReadAllText(Path.Combine(templatePath, viewName));

    string renderedText = Razor.Parse(text, zonesVm);
    return renderedText;
}

it works correctly, and I see the result I expect to in the HTML.

Is there a way for me to get Razor to know what @Model is before it's compiled?

For reference, I'm using RazorEngine and not the ordinary MVC Razor stuff.

like image 885
DaveDev Avatar asked Jan 27 '26 15:01

DaveDev


1 Answers

You're already in a code block. You don't need the @ before model. The @ is used to transition into a code block from html.

like image 102
Patrick Hallisey Avatar answered Jan 30 '26 05:01

Patrick Hallisey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!