我有一个ASP.NET MVC应用程序,可以显示学生俱乐部中每个学生的每周任务。它有2个不同的.cshtml文件,一个用于显示数据库中的值(Index.cshtml),另一个用于编辑值并保存到SQL Server数据库(Edit.cshtml)
CREATE TABLE [dbo].[DaysOftheWeek](
[DayName] [varchar](10) NULL,
[ShortWeekName] [varchar](10) NULL
,
CONSTRAINT [PK_DayName] PRIMARY KEY NONCLUSTERED
(
[ShortWeekName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
INSERT INTO [dbo].[DaysOftheWeek](DayName,ShortWeekName) Values('S','Sunday')
INSERT INTO [dbo].[DaysOftheWeek](DayName,ShortWeekName) Values('M','Monday')
INSERT INTO [dbo].[DaysOftheWeek](DayName,ShortWeekName) Values('T','Tuesday')
Create Table dbo.StudentTasks(StudentID INT NOT NULL,DayAssigned Char(2) null, StudentMajor VARCHAR(200) NOT NULL);
ALTER TABLE dbo.StudentTasks WITH CHECK ADD CONSTRAINT [FK_day] FOREIGN KEY([DayAssigned])
REFERENCES [dbo].[DaysOftheWeek] ([ShortWeekName])
GO
ALTER TABLE dbo.StudentTasks CHECK CONSTRAINT [FK_day]
GO
INSERT INTO dbo.StudentTasks(StudentID,DayAssigned,StudentMajor) Values (1,'M','Accounts')
INSERT INTO dbo.StudentTasks(StudentID,DayAssigned,StudentMajor) Values(2,'T','Math')
我能够使用实体数据模型/控制器和视图显示Index.cshtml中的值。 我在编辑时遇到问题。
这是我的Edit.cshtml
的一部分<div class="form-group">
@Html.LabelFor(model => model.DayAssigned, htmlAttributes: new { @class = ".col-form-label col-md-2" })
<div class="col-md-10">
@Html.RadioButtonFor(model => model.DayAssigned, "S") Sunday
@Html.RadioButtonFor(model => model.DayAssigned, "M") Monday
@Html.RadioButtonFor(model => model.DayAssigned, "T") Tuesday
</div>
</div>
我不知道如何使用数据库中的值填充单选按钮。 感谢帮助 先生