我首先使用 EF 代码创建了以下课程模型:
public class Course
{
[Key]
public int CourseID { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(200)]
public string Description { get; set; }
[StringLength(50)]
public string Author { get; set; }
public DateTime UploadDate { get; set; }
public DateTime ExpiryDate { get; set; }
public int ParticipationPoints { get; set; }
public string BlobURL { get; set; }
//1 to many relationship
public virtual ICollection<Audit> Audits { get; set; }
public virtual ICollection<Content> Contents { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
public virtual ICollection<Feedback> Feedbacks { get; set; }
public virtual ICollection<Keyword> Keywords { get; set; }
public virtual ICollection<Target> Targets { get; set; }
public virtual ICollection<CourseSection> CourseSections { get; set; }
//many to many relationship
public virtual ICollection<MetaLearningUser> MetaLearningUsers { get; set; }
}
在设计模式下,我有以下 HTML 字段:
<form class="custom">
<fieldset>
<div class="row">
<div class="twelve columns">
<div class="row">
<div class="six columns">
<label>Course Title</label>
<input type="text">
</div>
<div class="six columns">
<label>Author</label>
<input type="text">
</div>
</div>
<div class="row">
<div class="six columns">
<label>Keywords</label>
<input type="text">
</div>
<div class="six columns">
<label>Metadata</label>
<input type="text">
</div>
</div>
<div class="row">
<div class="twelve columns">
<label>Description</label>
<textarea></textarea>
</div>
</div>
<div class="row">
<div class="six columns bottom20">
<label>Media type</label>
<div class="custom dropdown"> <a href="#" class="current"> Select media type </a> <a href="#" class="selector"></a>
<ul>
<li>Screencast</li>
<li>Podcast</li>
<li>Document</li>
<li>SCORM</li>
</ul>
</div>
</div>
<div class="six columns bottom20">
<label>Directory</label>
<div class="custom dropdown"> <a href="#" class="current"> Select subject </a> <a href="#" class="selector"></a>
<ul>
<li>Human Resources</li>
<li>IT Security</li>
<li>Corporate Governance</li>
<li>Health & Safety</li>
<li>Legal</li>
<li>IT Infrastructure</li>
<li>3rd Parties</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="six columns">
<label>Start date</label>
<input type="date" class="datefield">
</div>
<div class="six columns">
<label>End date</label>
<input type="date" class="datefield">
</div>
</div>
</div>
</div>
<a href="#" class="medium button bottom20">Submit</a>
</fieldset>
</form>
</div>
按下提交按钮时,如何将文本框中输入的数据保存到实体框架数据库中?