如何获取视图中asp-for中的coursename文本框值。当然是与外键链接的不同模型。我在使用 asp-for="CourseName" 时出现编译错误
public partial class Student
{
public int StdId { get; set; }
public string? StdName { get; set; }
public virtual ICollection<StudentCourse> StudentCourses { get; } = new List<StudentCourse>();
}
public partial class StudentCourse
{
public int StdId { get; set; }
public int CourseId { get; set; }
public string CourseName { get; set; }
public virtual Student? StdId { get; set; }
}
view
<input type="text" class="form-control" asp-for="CourseName" id="CourseName" name="CourseName">
controller
public IActionResult Save(IFormCollection formdata)
{
var coursedetails = formdata["CourseName"];
}
public partial class Student
{
public int StdId { get; set; }
public string? StdName { get; set; }
public virtual ICollection<StudentCourse> StudentCourses { get; } = new List<StudentCourse>();
}
public partial class StudentCourse
{
public int StdId { get; set; }
public int CourseId { get; set; }
public string CourseName { get; set; }
public virtual Student? StdId { get; set; }
}
view
<input type="text" class="form-control" asp-for="CourseName" id="CourseName" name="CourseName">
controller
public IActionResult Save(IFormCollection formdata)
{
var coursedetails = formdata["CourseName"];
}