方案麻烦从数据库
填充编辑复选框或下拉列表中有值我有利用jQuery的中继这样我可以保持在这种情况下,资质记录添加记录的问题。
问题
我遇到的问题是,我不能得到一个是/否下拉或复选框的工作或显示它从数据库中读取值。正如你所看到的,从屏幕截图我不能选择值显示在我的下拉列表中的“否”,如果选择了true,我将无法让我的复选框被选中“打勾”
评论代码区显示了我用过的一些方法,正如你所看到的,我不能完全绑定act(因为它是另一个类的一部分,所以我不能说“Model.historyLead”或者Model.act .historyLead。 我返回所有其他值,但它只是复选框或下拉列表不起作用。 我非常感谢任何帮助解决这个问题。 问候
我的编辑视图
@foreach (var item in Model.act)
{
<div data-repeater-item class="mt-repeater-item">
<div class="mt-repeater-input">
<label>Institution</label>
<input type="text" class="form-control" name="hisotryInput" value="@item.hisotryInput" />
</div>
<div class="mt-repeater-input">
<label>Description</label>
<div class="col-md-10">
@Html.TextArea("hisotrydescrip",item.hisotrydescrip, new { @class = "form-control", cols = 50, @rows = 5,@style="width:290px" })
</div>
</div>
<div class="mt-repeater-input">
<label>Lead Consultant?</label>
@*@Html.DropDownList("historyLead", null, String.Empty, new { @class = "form-control ", @Value = @item.historyLead })*@
@*@Html.CheckBox("historyLead", new { htmlAttributes = new { @class = "form-control",@[email protected] } })*@
<input type="checkbox" class="form-control" name="historyLead" [email protected] />
@*<select name="historyLead" >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</select>*@
</div>
和型号使用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace CARICAD_App.Models
{
public class repeatViewModel
{
[Display(Name = "textinput")]
public string textinput { get; set; }
}
public class CON_consultantInfoVM
{
[DisplayName("Age Range")]
public Nullable<int> ageRange { get; set; }
public int id { get; set; }
[DisplayName("Image")]
public string image { get; set; }
[DisplayName("Consultant ID")]
public string consultID { get; set; }
[DisplayName("First Name")]
[Required]
public string firstName { get; set; }
...
public REF_country REF_country { get; set; }
public REF_nationality REF_nationality { get; set; }
public List<actVm> act { get; set; }
}
public class actVm
{
public Nullable<int> id { get; set; }
public string consultID { get; set; }
public string textinput { get; set; }
public string untypedinput { get; set; }
public string dateinput { get; set; }
public string textareainput { get; set; }
public string radioinput { get; set; }
public string selectinput { get; set; }
public string activities { get; set; }
public string hisotryInput { get; set; }
public string historydateinput { get; set; }
public string hisotrydescrip { get; set; }
public string historydateinputTo { get; set; }
public string historyLead { get; set; }
public bool historyCo { get; set; }
public List<string> multipleselectinput { get; set; }
}
}
在问题中包含你的代码,而不是它的图像。 –
@StephenMuecke新增了它,但主要是为了显示我的模型循环 – Niana
您的复选框没有任何意义。如果'historyLead'的初始值是'“No”',那么它会生成'value =“No”',所以如果它被选中,它会回传'“No”',如果它没有被选中,它将不会回传任何东西。同上是初始值是'“是”'如果勾选,它会回传'“是”'如果没有选中则回复。 –