Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing Blazor Razor component in VS with dual screens

Is there a way to open Razor component in Visual Studio with environment with dual screens . I'll love to have markup on one screen and @code {} section on other. While MVC developing usually markup is on one screen while JS is on other. Switching to Blazor C# replaces JS,But my mind is still mapped to read markup from one while is code on other. Can we create component with code separated from markp but still connected. enter image description here

like image 573
adopilot Avatar asked Jan 16 '20 13:01

adopilot


People also ask

Can Blazor components be nested?

In the Blazor application, a component can also be nested inside another component using the HTML syntax. For example, if you want to nest counter component inside the index component then you need to use <Counter /> within the Index component.

Can you use Razor components without Blazor?

If you build a client blazor, it can make webapi to the mvc server. if you meant if you could use razor components with razor views or razor pages, then no. They are only for building blazor applications.

How do you construct Blazor components?

Let's create a Blazor component to display details about the employees of an organization. To add a component to the project, right-click on the Pages folder and choose Add -> Razor Component. Refer to the following image. In the Add New Item- Blazor App dialog, provide the name EmployeeCard and click Add.


1 Answers

You can use the code behind with a partial class :

MyComponent.razor

<h1>Thi is a component @Title</h1>

MyComponent.razor.cs

public partial class MyComponent
{
      [Parameter]
      public string Title { get; set; }
}

enter image description here

This is a 3.1 future, before 3.1 you cannot use partial class be inherits from class deriving from Microsoft.AspNetCore.Components.ComponenBase

before 3.1

MyComponent.razor

@inherits MyComponentModel
<h1>Thi is a component @Title</h1>

MyComponent.razor.cs

using Microsoft.AspNetCore.Components;

public class MyComponentModel : ComponentBase
{
      [Parameter]
      public string Title { get; set; }
}


like image 79
agua from mars Avatar answered Sep 22 '22 14:09

agua from mars