【发布时间】:2020-01-14 14:18:09
【问题描述】:
我有一个名为 Patient 的模型类,一个处理与 Patient 相关的服务的类,以及一个接口。除接口外,所有内容都是公共的,并且都在单独的文件中。当我尝试将 Razor 页面上的 InputText 绑定到患者属性时,ide 找不到它们。
剃须刀页面:
@using BlazorApp.Data;
<EditForm Model="@patient">
<div class="col-12 row">
<label class="col-2 font-weight-bold">first name: </label>
<InputText class="form-control col-3" @bind-Value="patient.Name"/>
placeholder="first name" />
</div>
</EditForm>
@code {
public Patient patient {get;set;}
protected override void OnInitialized()
{
patient = new Patient();
}
}
模型类:
public class Patient
{
public int ID { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public Patient(){}
public Patient(int id, string name, string lname, DateTime date)
{
ID = id;
Name = name;
LastName = lname;
DateOfBirth = date;
}
}
【问题讨论】:
-
问题在于命名空间...在 _Imports.razor 文件中设置正确的引用
-
将命名空间添加到导入文件中,问题仍然存在。 @enet
-
这些类的命名空间是什么?您是否尝试在使用它们的组件中添加 using 指令?
-
命名空间是 blazor,是的,它们也使用 using 指令添加。 @enet
-
更改命名空间,不要再使用 blazor 这个词了。我不认为它是相关的,但你仍然不必定义这样的命名空间。现在,请将所有相关的命名空间和相关的 using 语句复制并粘贴到这里,以便我亲眼看到。
标签: c# asp.net-core razor blazor