C
C#3w ago
DaClownie

Parameter count mismatch error when trying to change what is being displayed in a Blazor application

@foreach (var assessment in AssessmentService.Assessments)
{
var editAssessment = false;
var updateAssessment = assessment;
if (editAssessment)
{
<div style="border: 2px solid #000000; border-radius: 10px; padding: 10px;">
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => editAssessment = false" />
</EditForm>
</div>
}
else if (!editAssessment)
{
<div style="border: 2px solid #000000; border-radius: 10px; padding: 10px;">
<span>@assessment.Name</span>
<span>@assessment.Type</span>
<span>@assessment.DateStart</span>
<span>@assessment.DateEnd</span>
<span>
<button class="btn btn-primary"
onclick="@(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
</span>
<span>
<button class="btn btn-danger"
onclick="@(() => DeleteAssessment(assessment.Id))">
<i class="bi-trash3" />
</button>
</span>
</div>
}
}
@foreach (var assessment in AssessmentService.Assessments)
{
var editAssessment = false;
var updateAssessment = assessment;
if (editAssessment)
{
<div style="border: 2px solid #000000; border-radius: 10px; padding: 10px;">
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => editAssessment = false" />
</EditForm>
</div>
}
else if (!editAssessment)
{
<div style="border: 2px solid #000000; border-radius: 10px; padding: 10px;">
<span>@assessment.Name</span>
<span>@assessment.Type</span>
<span>@assessment.DateStart</span>
<span>@assessment.DateEnd</span>
<span>
<button class="btn btn-primary"
onclick="@(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
</span>
<span>
<button class="btn btn-danger"
onclick="@(() => DeleteAssessment(assessment.Id))">
<i class="bi-trash3" />
</button>
</span>
</div>
}
}
As it renders now, the else if portion of the code is working. It renders the Assessment. when clicking the edit button I get the error listed in the title. Will put the full error in a comment below this post.
No description
8 Replies
DaClownie
DaClownieOP3w ago
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Parameter count mismatch.
System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.MethodBaseInvoker.ThrowTargetParameterCountException()
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[Object](MulticastDelegate delegate, Object arg)
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync(Object arg)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs, Boolean waitForQuiescence)
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Parameter count mismatch.
System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.MethodBaseInvoker.ThrowTargetParameterCountException()
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[Object](MulticastDelegate delegate, Object arg)
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync(Object arg)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs, Boolean waitForQuiescence)
As far as I can tell, it should be monitoring for the changing of the state of the variable and removing the else if from displaying and rendering the if portion, but it errors while still keeping the else if displayed with the above code. I'm sure I'm misinterpreting how the rendering works but I'm not quite sure how else to handle the displaying/editing in the same line
Nasdack
Nasdack3w ago
You're missing some @ notations here
No description
Nasdack
Nasdack3w ago
I'm not sure if this could be the issue because it's usually gracefully ignored but at least try
DaClownie
DaClownieOP3w ago
I tried putting @ in both of those locations but it gets an error for that syntax. On the first, OnValidSubmit is a Parameter of the Editform component and its syntax is like shown if i'm passing a variable (as far as I can tell), on the second, the@onclick is to handle the EventCallback for the mouse event and set the local variable, editAssessment to false However, that block of code isn't even getting a chance to run when setting breakpoints Ok, so for some additional information: if I change
<button class="btn btn-primary"
onclick="@(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
<button class="btn btn-primary"
onclick="@(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
the onclick will throw an error before even attempting to run that. I have a breakpoint there and it never hits for it. It gets the parameter mismatch instantly. If I change that call to
<button class="btn btn-primary"
@onclick="(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
<button class="btn btn-primary"
@onclick="(() => editAssessment = true)">
<i class="bi-pencil-square" />
</button>
it will run the code, but the value of editAssessment doesn't change to true like it it set to do, and it never renders the edit block of code as shown below:
@if (editAssessment)
{
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => editAssessment = false" />
</EditForm>
}
@if (editAssessment)
{
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => editAssessment = false" />
</EditForm>
}
Nasdack
Nasdack3w ago
Yeah you need to add parentheses
DaClownie
DaClownieOP3w ago
Ok, updated and same effect. Unfortunately I’m not even reaching the point that those elements are displaying. It’s failing prior. I may need to just come up with a different approach. Push the edit to a new page and move on despite it being less than optimal.
glhays
glhays3w ago
Try this.
<button class="btn btn-primary" @onclick="() => { editAssessment = true; StateHasChanged(); }">
<i class="bi-pencil-square" />
</button>

@if (editAssessment)
{
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => { editAssessment = false; StateHasChanged(); }" />
</EditForm>
}
<button class="btn btn-primary" @onclick="() => { editAssessment = true; StateHasChanged(); }">
<i class="bi-pencil-square" />
</button>

@if (editAssessment)
{
<EditForm Model="updateAssessment" OnValidSubmit="() => HandleEditSubmit(updateAssessment)">
<InputText id="name" placeholder="Name:" @bind-Value="updateAssessment.Name" />
<InputDate Type="InputDateType.DateTimeLocal" id="dateStart" @bind-Value="updateAssessment.DateStart" />
<InputDate Type="InputDateType.DateTimeLocal" min="@updateAssessment.DateStart" id="dateEnd" @bind-Value="updateAssessment.DateEnd" />
<button type="submit" class="btn btn-primary mt-4">Submit</button>
<button type="button" class="btn btn-close" @onclick="() => { editAssessment = false; StateHasChanged(); }" />
</EditForm>
}
DaClownie
DaClownieOP3w ago
Yep, still no luck. Never displays the @if (editAssessment) block. I'm going to find a new way and move on. Maybe having an edit modal overlay instead would be easier. just a div centered in the middle of the screen being passed an object. How hard can it be lol Yea, going the modal method was so much easier. I may revisit this later just to figure out why it wouldn't work because its a good learning, but in the vein of just carrying on with my work, modal will be the way ty for your help, both of you

Did you find this page helpful?