我已经找到了从下拉列表中过滤结果的示例...但在我发现的所有示例中,下拉列表使用与结果相同的模型。我尝试在一个模型的局部视图中抛出下拉,而在另一个模型的另一个视图中抛出结果……但它并没有起作用。在PHP、WinForms或MS Access中,这将是非常简单的,但在MVC中,做这么简单的事情似乎非常复杂。
我的模型很简单。我的联系人可以分配到具有桥接表/对象ContactGroups的组中:
public class Contacts
{
public int ContactsID { get; set; }
[Display(Name ="First Name")]
[Required]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
[Required]
public string LastName { get; set; }
[Display(Name = "Primary Phone")]
[Phone]
public string PrimaryPhone { get; set; }
[Display(Name = "Phone Type")]
public PhoneType PhoneType { get; set; }
[Display(Name = "PrimaryEmail")]
[EmailAddress]
public string PrimaryEmail { get; set; }
public virtual ICollection<MessageContacts> MessageContacts { get; set; }
public virtual ICollection<ContactGroups> ContactGroups { get; set; }
}
public class Groups
{
public int GroupsID { get; set; }
[Required]
public string GroupName { get; set; }
public virtual ICollection<ContactGroups> ContactGroups { get; set; }
}
public class ContactGroups
{
public int ContactGroupsID { get; set; }
[Required]
public int ContactID { get; set; }
[Required]
public int GroupID { get; set; }
}我正在尝试使用可用组填充下拉列表,并从下拉选择中筛选组中的所有联系人。我想这对于有经验的EF的你来说可能很简单,所以我非常感谢你的帮助!
发布于 2017-02-14 22:46:25
请注意,POHeaderId下拉选项已填充到文档ready...因此,一旦他们选择了一个POheaderID,它就会用操作返回的相关选择填充OldLocation。
这里有一个概要--也许你可以做类似的事情,或者你可能会找到一个更合适的解决方案。
视图的一部分...
<div class="form-group form-group-no-bott-marg">
@Html.LabelFor(model => model.PoHeaderId, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("PoHeaderId", String.Empty)
@Html.Label("NB: XXXXXX moved by specific Purchase Order", new { style = "color: red" })
</div>
</div>
<div class="form-group form-group-no-bott-marg">
@Html.LabelFor(model => model.OldLocationId, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("OldLocationId", String.Empty)
@Html.ValidationMessageFor(model => model.OldLocationId)
</div>
</div>更改POHader时的javascript......for的一部分.....
$('#PoHeaderId').change(function() {
$('#confirm').text('');
var poId = $("#PoHeaderId :selected").val();
var items = [];
//Call the action to get the list in JSON format
var url = "@Url.Action("Locations", "Utilities")";
//alert(url);
window.ShowOrHideProgress(true);
$.ajax({
url: url,
type: 'GET',
cache: false,
data: { locationId: 0, poHeaderId: poId },
success: function (resultantJsonData) {
for (var i = 0; i < resultantJsonData.length; i++) {
items.push("<option value=" + resultantJsonData[i].Value + ">" + resultantJsonData[i].Text + "</option>");
}
$('#OldLocationId').html(items.join(' '));
}
});});
它所说的行动……
public ActionResult Locations(int locationId, int poHeaderId = 0)
{
var locList = StockMovesHeaderViewModelHelper.GetLocations(db, locationId, poHeaderId);
var tmpList = new SelectListWithSelect(true);
foreach (var l in locList)
{
tmpList.Add(new SelectListItem { Text = l.Description, Value = l.FulfilmentLocationID.ToString() });
}
return Json(tmpList, JsonRequestBehavior.AllowGet);
}https://stackoverflow.com/questions/42228343
复制相似问题