conficient / BlazorTemplater

A library that generates HTML (e.g. for emails) from Razor Components
Apache License 2.0
146 stars 16 forks source link

CS 7036 Error Even without Base Class Inheritance #17

Closed ramjet69 closed 2 years ago

ramjet69 commented 2 years ago

Hello,

I am unable to figure out why I am getting a CS7036 on even the most basic model when using the Fluent Set.

Here is my model:

public class ConfirmUserEmailViewModel
{
    public string Name { get; set; }
    public string ConfirmUrl { get; set; }
}

Here is my razor:

<p>Welcome @Model.Name,</p>
<p>Please confirm your email by <a href='@Model.ConfirmUrl'>clicking here</a>.</p>
<p>If you prefer you can copy and paste this link into your browser of choice.</p>
<br />
<p>@Model.ConfirmUrl</p>
<br />

@code {
    [Parameter] public ConfirmUserEmailViewModel Model { get; set; }
}

image

What am I doing wrong?

TIA

conficient commented 2 years ago

I've often made this mistake too myself! The setter syntax is .Set(x => x.Property, Value) - note the comma not equals

So change your code to

var viewResult = new ComponentRenderer<ConfirmUserEmail>()
   .Set(x => x.Model, viewModel)
  .Render();

That should do it

conficient commented 2 years ago

Just realised this was my error in my answer on your StackOverflow question - apologies for misleading you!

ramjet69 commented 2 years ago

@conficient No Worries!

Thanks