razor

Execute async method on button click in blazor

蓝咒 提交于 2020-05-28 13:42:39
问题 I created a "Razor Components" project. I am trying to execute an asynchronous method when pressing a button, but could not figure out the syntax yet. This is my Index.razor : @page "/" @inject GenericRepository<Person> PersonRepository // ... @foreach (var person in persons) { <button onclick="@(() => Delete(person.Id))">❌</button> } @functions { // ... async void Delete(Guid personId) { await this.PersonRepository.Delete(personId); } } When I click the button, nothing happens. I tried

How to reset custom validation errors when using editform in blazor razor page

蓝咒 提交于 2020-05-27 06:26:31
问题 I have an editform using an editcontext: <EditForm OnValidSubmit="HandleValidSubmit" EditContext="_editContext" Context="auth"> <DataAnnotationsValidator /> <input type="time" @bind-value="_foodTruck.EndDelivery" @onkeydown="@(q=>ResetValidation("EndDelivery"))" > <ValidationMessage For="() => _foodTruck.EndDelivery" /> <input type="time" @bind-value="_foodTruck.StartDelivery" @onkeydown="@(q=>ResetValidation("StartDelivery"))" > <ValidationMessage For="() => _foodTruck.StartDelivery" />

How do I insert spaces within a razor Code block?

自古美人都是妖i 提交于 2020-05-25 17:33:49
问题 VS2013, MVC5, Razor, VB I want spaces in front of the word 'Answered'. How do I force spaces into the following Razor code block? @Code If Model.DisplayAnsweredFlag Then @If Model.Answered Then @Html.Raw("Answered") End If End If End Code In html.raw(), spaces by themselves or spaces in of front text don't seem to get coded into the page. But I also can't use '&nbsp' or '@&nbsp' in a Code Block because it's incorrect syntax. If I'm coding with a poor technique, please advise, or if there is a

How do I insert spaces within a razor Code block?

我的梦境 提交于 2020-05-25 17:30:46
问题 VS2013, MVC5, Razor, VB I want spaces in front of the word 'Answered'. How do I force spaces into the following Razor code block? @Code If Model.DisplayAnsweredFlag Then @If Model.Answered Then @Html.Raw("Answered") End If End If End Code In html.raw(), spaces by themselves or spaces in of front text don't seem to get coded into the page. But I also can't use '&nbsp' or '@&nbsp' in a Code Block because it's incorrect syntax. If I'm coding with a poor technique, please advise, or if there is a

Calling a C# function by a HTML button

假如想象 提交于 2020-05-25 04:52:47
问题 What I’m trying to do is to call function by a button. i'll leave you with a simple code that doesn't work! : @{ protected void print() { @<p>WELCOME!</p> } } <form> <button onclick="print" value="CLICK ME"/> </form> any idea on how to accomplish what im trying to do in the code above? NOTE: IM NOT USING MVC 回答1: You can't do it like this.It is not ASP.NET WebForms . So if you want to Execute a C# function on Button click in Razor, you must could create a Controller ,then when user clicks a

Forms inside foreach loop in Razor Page

。_饼干妹妹 提交于 2020-05-23 10:43:33
问题 I have a standard Razor Page that lists all Orders in my database. It's coded pretty standard: IList<Order> bind property in page model, OnPost method. However, each of the records in a table has a column with a select element that shows the current status of the order, and a button to save the new status if the user decides to change it. Sort of an inline edit of the status for each row. So I have a foreach loop in my page that cycles through all my orders: @foreach (var item in Model.Orders

Forms inside foreach loop in Razor Page

允我心安 提交于 2020-05-23 10:41:26
问题 I have a standard Razor Page that lists all Orders in my database. It's coded pretty standard: IList<Order> bind property in page model, OnPost method. However, each of the records in a table has a column with a select element that shows the current status of the order, and a button to save the new status if the user decides to change it. Sort of an inline edit of the status for each row. So I have a foreach loop in my page that cycles through all my orders: @foreach (var item in Model.Orders

ASP.NET Core - pass Class instance parameter from razor View to formaction

柔情痞子 提交于 2020-05-17 06:01:39
问题 Our team has inherited a system that we're trying to improve as we go along. One thing we've noticed in our razor Views is many cases where different Controller Actions are written, that look like they could be parameterised. for example, we have something a bit like this... ProcessSubmissionView.cshtml <button class="btn" type="submit" id="process-english-submission" formaction="ProcessWelshSubmission" formmethod="post">Process Welsh Submission</button> <button class="btn" type="submit" id=

Razor code EditorFor showing '�' as default?

左心房为你撑大大i 提交于 2020-05-16 08:06:26
问题 In my Form, there is a textbox, in razor code using EditorFor and the type given for this is Char . But it always shows a '�' as default, what's that mean? is this because of char type? please look at the picture 回答1: This � is the invalid unicode code point glyph. It is what you will see in most browsers when they encounter the null character '\0' (U+0000). This happens to be the default value of the .NET char data type. Three workarounds: substitute a valid char for the default, for example

Check whether a char is null or empty in razor view

大城市里の小女人 提交于 2020-05-16 06:00:48
问题 It seems to be a fundamental question, but I could not find the exact answer. I am passing a null or empty char value ('\0' in c#) from Model to View, and in View I need to check whether the char is equal to null or empty. I have tried the following: if ("@Model.CharValue" != "\0") {...} if ("@Model.CharValue" != '\0') {...} if ("@Model.CharValue" != ' ') {...} None of them gave me the proper check. and using alert("@Model.CharValue"); The pop up gave me this character, which I have no idea