我已经在那里我已经建立了各种各样的形式的页面。 我有2个下拉列表(profilelist & salarylist)。如何如果选择/一个ListItem,如果项目在下拉列表中选择要检查并启用/禁用文本框没有选择
我有这种形式3个文本框。我想要做的事情:
我有2个箱子,我在这里创建一个新的配置文件和一个新的工资组,并将新的配置文件添加到profillist amd,并将该工资组添加到工资清单中。
现在我想直到salarylis和profillist两个项目被选中禁用第三个框。一旦选择了项目,应启用文本框。
我的观点:
@model KUMA.Models.EmployeeCardAdminModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row bgwhite">
<div class="twelve columns">
<h2>Administration KUMA</h2>
<div class="row bgwhite">@using (Html.BeginForm("Index", "Admin"))
{
<div class="three columns">
@Html.DropDownList("UserId", (SelectList)ViewBag.UserId, "--Välj anställd--")
</div>
<div class="three columns" style="margin-right:457px !important;">
@Html.DropDownList("Salaryid", (SelectList)ViewBag.Salaryid, "--Välj LöneGrupp--")
<input style="float:left;" type="submit" value="Knyt" />
</div>
}
@using (Html.BeginForm("Kompetens", "KumaAdmin"))
{
<div class="three columns" style="margin-right: 627px;">
<h6>Kompetenser</h6>
<div style="width:456px;"> @Html.ListBox("kompetensId", (SelectList)ViewBag.KomId, new { placeholder = "Kompetenser" })</div><br/>
@Html.TextBoxFor(mm => mm.Kompetens, new { placeholder = "Ange Kompetens" })
@*@Html.TextBoxFor(mm => mm.KompetensTest, new { placeholder = "Kompetens" })
@Html.TextAreaFor(mm => mm.KompetensTest, new { placeholder = "Kompetens", rows="5", cols="80" })*@
<input type="submit" style="margin-right: 205px;" value="Skapa"/><br/><br/>
</div>
}
@using (Html.BeginForm("Index", "KumaAdmin"))
{
<div class="three columns" style="margin-right: 627px;">
@* <input name="profileTxtBox"type="text" style="width:97px; height:28px;" value="" />*@
@Html.TextBoxFor(mm => mm.Profile, new { placeholder = "Ange Profil" })
@Html.TextBoxFor(mm => mm.SalaryGroup, new { placeholder = "Ange LöneGrupp" })
<input type="submit" value="Skapa"/>
</div>
}
@* <div class="one columns" style=" margin-left: 100px;margin-right: 164px; margin-top: -33px;">
<input name="profileTxtBox"type="submit" style="width:100px;" value="Add" />
</div>*@
<div class="five columns"></div>
</div>
</div
>
控制器:
public class AAdminController : Controller
{
static List<Employee> list = new List<Employee>();
//EmployeeCardAdminModel employee = new EmployeeCardAdminModel();
//
// GET: /Admin/
//[Authorize(Roles = "Admin")]
[HttpGet]
public ActionResult Index()
{
ViewBag.UserId = new SelectList(list, "Id", "Profile");
ViewBag.Salaryid = new SelectList(list, "Id", "SalaryGroup");
ViewBag.KomId = new SelectList(list, "Id", "Kompetens");
ModelState.Clear();
return View("Index");
}
[HttpPost]
// submit for profile & salary box
public ActionResult Index(Models.EmployeeCardAdminModel e)
{
if (string.IsNullOrEmpty(e.Profile) == false && string.IsNullOrEmpty(e.SalaryGroup) == false)
{
// adda a new employye to the list and set the values from the parameter to the model
list.Add(new Employee
{
Id = e.Id + 1,
Profile = e.Profile,
SalaryGroup = e.SalaryGroup
});
}
return (Index());
}
[HttpPost]
// submit for knowledge box
public ActionResult Kompetens(Models.EmployeeCardAdminModel e)
{
if (string.IsNullOrEmpty(e.Kompetens) == false)
{
// adda a new employye to the list and set the values from the parameter to the model
list.Add(new Employee
{
Kompetens = e.Kompetens
});
}
return (Index());
}
最后我的模型(注意emplyee类是一样的我的模型,具有相同属性但我认为最好的做法是最好将这些分开。):
public class EmployeeCardAdminModel
{
public string Profile { get; set; }
public int Id { get; set; }
public string SalaryGroup { get; set; }
public string Kompetens { get; set; }
}
的方式,我会normaly做,这是调用所需的列表,并检查是否选择指数大于零较大,但问题是我不知道如何从控制器访问以正确的方式列表,所以我可以访问它中的项目。我怎么能得到一个文本框上的ID?我需要这个能够禁用/启用正确的文本框。
林很新的MVC和我做项目,因此所有的建议表示赞赏学习。
谢谢!