我有一个实体框架模型(课程),它包含一个(学生)实体的集合。
我在前端使用AngularJS,并将课程实体传递给我的视图。
在视图中,我需要使用Html.NameFor()为模型的每个属性创建唯一的名称,以便在传递给应用程序接口时可以映射回模型。
// Course Model
class Course {
ICollection<Student> Students;
}
// Student Model
class Student {
public string FullName {get; set;}
}
// MyView.vbhtml
@ModelType Course
<input type = 'text' name = '@Html.NameFor(Function (Model) Model.Students(0).FullName)'/>我希望输入字段的名称是'Students(0).FullName‘。
但它就像是“FullName”一样。
有没有什么方法可以让我得到想要的结果?
非常感谢
发布于 2019-02-02 06:21:41
我不是100%清楚你是想让它是Students(0).Fullname作为文字字符串还是集合中学生的实际姓名,但无论哪种方式,你都必须循环它
for(int i =0; i < Students.Count; i++)
{
<input type='text' name=Students(i).FullName
}我会以文字字符串的形式给出它,即学生(1).FullName或学生(2).FullName
for(int i =0; i < Students.Count; i++)
{
<input type='text' name=Students[i].FullName
}会给出它作为它们的实际名称(注意[]而不是())
https://stackoverflow.com/questions/54478391
复制相似问题