这是一个用于对医生进行评级的混合(Web 表单和 MVC).NET 网站。下面是我的 GridView。用户可以通过单击单选按钮进行评分,评分应该保留在 Doctor 对象中,并且 Doctor 对象应该能够显示当前用户的评分和用户的平均评分。我将如何在会话中存储对象?没有登录。
<asp:ObjectDataSource ID="ObjectDataSourceDoctor" runat="server" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetDoctor" TypeName="MidtermApplication.Models.TestApplicationDoctorRepo" UpdateMethod="Update" DataObjectTypeName="MidtermApplication.Models.Doctor">
</asp:ObjectDataSource>
<asp:GridView ID="GridViewDoctor" runat="server" DataSourceID="ObjectDataSourceDoctor" AutoGenerateColumns="False" OnSelectedIndexChanged="GridViewDoctor_SelectedIndexChanged">
<Columns>
<asp:ImageField DataImageUrlField="DoctorPicture" HeaderText="DoctorPicture">
</asp:ImageField>
<asp:BoundField DataField="DoctorName" HeaderText="DoctorName" SortExpression="DoctorName" />
<asp:BoundField DataField="DoctorSpecialty" HeaderText="DoctorSpecialty" SortExpression="DoctorSpecialty" />
<asp:TemplateField HeaderText="Rate Now">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="RateNow" Text="1"></asp:RadioButton>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="RateNow" Text="2"></asp:RadioButton>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="RateNow" Text="3"></asp:RadioButton>
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="RateNow" Text="4"></asp:RadioButton>
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="RateNow" Text="5"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField AccessibleHeaderText="Save Rating" HeaderText="Save Rating" Text="Save" ButtonType="Button" />
<asp:CheckBoxField DataField="fave" HeaderText="Favorite" SortExpression="fave" InsertVisible="False" />
</Columns>
</asp:GridView>
后面的代码:
public partial class Rating : System.Web.UI.Page
{
TestApplicationDoctorRepo repo;
Doctor doctors;
protected List<Doctor> context;
RateableDoctor DoctorRating = new RateableDoctor();
protected void Page_Load(object sender, EventArgs e)
{
TestApplicationDoctorRepo.InitApp(this);
}
protected override void OnLoad(EventArgs e)
{
context = (List<Doctor>)Application["doctors"];
if (context == null)
{
context = new TestDoctorRepository().GetDoctor();
Application.Lock();
Application["doctors"] = context;
Application.UnLock();
}
base.OnLoad(e);
}
protected void SaveRepo()
{
Application.Lock();
Application["doctors"] = context;
Application.UnLock();
}
}
}