我正在尝试开发一个小型工资单项目。我首先使用代码创建了类。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace HumanResource.Models
{
public class SalaryBifurcation
{
[Key]
public int EmployeeSalaryTypeID { get; set; }
public string EmployeeSalaryTypeName { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace HumanResource.Models
{
public class EmployeeSalary
{
[Key]
public int EmployeeSalaryID { get; set; }
public int EmployeeId { get; set; }
public EmployeeDetail Employees { get; set; }
public int EmployeeSalaryTypeID { get; set; }
public virtual ICollection<SalaryBifurcation> SalaryBifurcation { get; set; }
public double SalaryAmount { get; set;}
}
}
我想创建一个视图,其中显示了员工记录的下拉列表,并在此框下显示了 SalaryBifurcation 列表的列表以及第二类的 SalaryAmount 属性。
我的目标不是硬编码SalaryBifurcation
项目,例如基本工资、房屋租金津贴等,而是让用户添加SalaryBifurcation
项目。
我的 HTTPGet 创建是
public ActionResult CreateEmployeeSalary()
{
ViewBag.EmployeeId = new SelectList(db.EmployeesSalaries, "EmployeeId", "FullName");
ViewBag.salarybifurcation = db.SalaryBifurcation.ToList();
return View();
}
我的观点
@model HumanResource.Models.EmployeeSalary
@{
ViewBag.Title = "CreateEmployeeSalary";
}
<h2>CreateEmployeeSalary</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Employee Salary</legend>
<div class="editor-label">
@Html.Label("employee id")
</div>
<div class="editor-field">
@Html.DropDownList("EmployeeId", string.Empty)
</div>
@foreach (var item in ViewBag.salarybifurcation)
{
@item.EmployeeSalaryTypeName
@Html.EditorFor(Model => Model.SalaryAmount)
<br />
}
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
任何人都可以帮助我为这个视图开发 [HTTPPost] 创建方法,因为我尝试了几个但没有工作。