【发布时间】:2015-08-26 11:42:19
【问题描述】:
我是 ASP.Net MVC 的新手
我想显示一个不同的视图来选择一所学校和一个查伦,然后插入所选查伦的 ID 和所有学生的 ID(所选学校的)要插入到加入表中,即。 ChallanAndStudents 表
我有以下实体
tbl.FeeChallan,
tbl.Students (Students belong to different schools),
tbl.ChallanAndStudents (the joining Table of tbl.FeeChallan and tbl.Students )
tbl.Schools
联接表有一个StudentID 和FeeChallanID
正如业务逻辑所说:FeeChallans 可以来自单个学生或整个学校。
在选择整个学校的情况下,我将允许用户从 DropDownList 中选择 School,并从第二个 DropDownList 中选择 ChallanNumber。
然后在提交时,我必须插入ChallanFormID 和StudentID(所选学校的所有学生到加入表中)
查看模式:
public class vmAssignChallanToWholeSchool
{
public int ChallanFormID { get; set; }
public int SchoolID { get; set; }
}
控制器:
public ActionResult AssignChallanToSchool()
{
vmAssignChallanToWholeSchool ChallanToSchool = new vmAssignChallanToWholeSchool();
ViewBag.ChallanForm = new SelectList(db.ChallanForm.ToList(), "ChallanFormID", "ChallanFormNumber", ChallanToSchool.ChallanFormID);
ViewBag.Schools = new SelectList(db.Schools, "ID", "Name", ChallanToSchool.SchoolID);
return View();
}
查看:
@model EBS_MVC.ViewModels.vmAssignChallanToWholeSchool
@{
ViewBag.Title = "AssignChallanToSchool";
}
<h2>AssignChallanToSchool</h2>
<div class="form-group">
@Html.LabelFor(model => model.ChallanFormID, "ChallanID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList( "ChallanForm", new SelectList(ViewBag.ChallanForm))
@Html.ValidationMessageFor(model => model.ChallanFormID, "", new { @class = "text-danger" })
</div>
</div>
我是否需要一个自定义 ViewModel 来完成这项工作,就像上面提到的那样?
Hit and Try 列表:
EntityType: EntitySet 'vmAssignChallanToWholeSchools' 基于类型 没有定义键的“vmAssignChallanToWholeSchool”。 在此处输入图片说明
System.Web.HttpException:数据绑定: “System.Web.Mvc.SelectListItem”不包含具有 名称“ChallanFormID”。
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework